LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package big | 5 package big |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/hex" | 9 "encoding/hex" |
10 "testing" | 10 "testing" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 var z2 Int | 135 var z2 Int |
136 z2.SetBytes(mulBytes(a, b)) | 136 z2.SetBytes(mulBytes(a, b)) |
137 | 137 |
138 return z1.Cmp(&z2) == 0 | 138 return z1.Cmp(&z2) == 0 |
139 } | 139 } |
140 | 140 |
141 | 141 |
142 func TestMul(t *testing.T) { | 142 func TestMul(t *testing.T) { |
143 if err := quick.Check(checkMul, nil); err != nil { | 143 if err := quick.Check(checkMul, nil); err != nil { |
144 t.Error(err) | 144 t.Error(err) |
145 } | |
146 } | |
147 | |
148 | |
149 var facts = map[int]string{ | |
150 0: "1", | |
151 1: "1", | |
152 2: "2", | |
153 10: "3628800", | |
154 20: "2432902008176640000", | |
155 100: "933262154439441526816992388562667004907159682643816214685929" + | |
156 "638952175999932299156089414639761565182862536979208272237582" + | |
157 "51185210916864000000000000000000000000", | |
158 } | |
159 | |
160 | |
161 func TestFact(t *testing.T) { | |
162 for n, s := range facts { | |
163 var z Int | |
164 f := z.Fact(uint(n)).String() | |
165 if f != s { | |
166 t.Errorf("%d! = %s; want %s", n, f, s) | |
167 } | |
168 } | |
169 } | |
170 | |
171 | |
172 func BenchmarkFact(b *testing.B) { | |
173 var z Int | |
174 for i := 0; i < b.N; i++ { | |
175 z.Fact(1e5) | |
176 } | 145 } |
177 } | 146 } |
178 | 147 |
179 | 148 |
180 type fromStringTest struct { | 149 type fromStringTest struct { |
181 in string | 150 in string |
182 base int | 151 base int |
183 out int64 | 152 out int64 |
184 ok bool | 153 ok bool |
185 } | 154 } |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 func TestInt64(t *testing.T) { | 696 func TestInt64(t *testing.T) { |
728 for i, testVal := range int64Tests { | 697 for i, testVal := range int64Tests { |
729 in := NewInt(testVal) | 698 in := NewInt(testVal) |
730 out := in.Int64() | 699 out := in.Int64() |
731 | 700 |
732 if out != testVal { | 701 if out != testVal { |
733 t.Errorf("#%d got %d want %d", i, out, testVal) | 702 t.Errorf("#%d got %d want %d", i, out, testVal) |
734 } | 703 } |
735 } | 704 } |
736 } | 705 } |
LEFT | RIGHT |