-
Notifications
You must be signed in to change notification settings - Fork 0
/
primid_test.go
38 lines (31 loc) · 870 Bytes
/
primid_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
package primid
import (
"testing"
"math"
)
// TestInverse tests the inverse calculator
func TestInverse(t *testing.T){
var inv,err = Inverse(1580030173)
if err != nil {
t.Fatalf("failed to invert prime: %s", err.Error())
}
if inv != 59260789 {
t.Fatalf("inverse not valid, expected %d, got %d", 59260789, inv)
}
}
// TestGenerator crudely tests the generator by checking whether some numbers go through successfully
func TestGenerator(t *testing.T) {
var generator, err = NewGenerator(1580030173, 12312)
if err != nil {
t.Fatalf("failed to initialize generator: %s", err.Error())
}
const increment = math.MaxInt32 / 100
for num := uint64(0); num < math.MaxInt32; num += increment {
var enc=generator.Encode(num)
var dec=generator.Decode(enc)
t.Logf("%d => %d => %d\n", num,enc,dec)
if num != dec {
t.Fatal("decoding failed")
}
}
}