-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
60 lines (54 loc) · 1.28 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import "testing"
func equalIntSlices(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func TestMillerRabin(t *testing.T) {
n1 := int64(592701729979) // true
if !MillerRabin(n1) {
t.Errorf("got false, expected true for %d", n1)
}
n2 := int64(100) // true
if !MillerRabin(n2) {
t.Errorf("got false, expected true for %d", n2)
}
n3 := int64(101) // false
if MillerRabin(n3) {
t.Errorf("got true, expected false for %d", n3)
}
}
// Note that as tests go, this is especially wonky! It will sometimes fail since it has a random number
func TestMillerRabin_OddComposites(t *testing.T) {
n2 := int64(55) // true
if !MillerRabin(n2) {
t.Errorf("got false, expected true for %d", n2)
}
n3 := int64(49) // true
if !MillerRabin(n3) {
t.Errorf("got false, expected true for %d", n3)
}
n4 := int64(75) // true
if !MillerRabin(n4) {
t.Errorf("got false, expected true for %d", n4)
}
n5 := int64(87) // true
if !MillerRabin(n5) {
t.Errorf("got false, expected true for %d", n5)
}
n6 := int64(91) // true
if !MillerRabin(n6) {
t.Errorf("got false, expected true for %d", n6)
}
n7 := int64(93) // true
if !MillerRabin(n7) {
t.Errorf("got false, expected true for %d", n7)
}
}