-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsslfsr16_test.go
77 lines (61 loc) · 1.54 KB
/
sslfsr16_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package sslfsr
import (
"math"
"slices"
"testing"
"github.com/stretchr/testify/assert"
)
func Test16BitShift(t *testing.T) {
t.Parallel()
for i := range math.MaxUint16 + 1 {
reg := NewSSLFSR16(0) // not using interval
reg.register = uint16(i)
for range math.MaxUint16 {
reg.Shift()
}
assert.Equal(t, uint16(i), reg.register, "65535 shifts should result in starting state")
}
}
func Test16BitSubShift(t *testing.T) {
t.Parallel()
for i := range math.MaxUint16 {
reg := NewSSLFSR16(0)
reg.register = uint16(i)
for range math.MaxUint8 {
reg.SubShift()
}
assert.Equal(t, uint16(i), reg.register, "255 subshifts should result in starting state")
}
}
func Test16BitIntervals(t *testing.T) {
t.Skip("This test takes too long to run")
for _, interval := range Intervals16Bits() {
reg := NewSSLFSR16(uint16(interval))
start := reg.register
reg.Next()
count := 1
for reg.register != start || reg.counter != 0 {
reg.Next()
count++
}
assert.Equal(t, reg.CalculateExpectedMaximalLength(), count, "should return to start state in ((2^16)-1)(%d+1) state changes", interval)
}
}
func TestNonIntervals16Bits(t *testing.T) {
t.Skip("This test takes too long to run")
intervals := Intervals16Bits()
for i := 2; i <= math.MaxUint16; i++ {
if slices.Contains(intervals, i) {
continue
}
reg := NewSSLFSR16(uint16(i))
start := reg.register
reg.Next()
count := 1
for reg.register != start || reg.counter != 0 {
reg.Next()
count++
}
assert.NotEqual(t, reg.CalculateExpectedMaximalLength(), count)
}
}