-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsslfsr8_test.go
91 lines (69 loc) · 1.65 KB
/
sslfsr8_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package sslfsr
import (
"math"
"slices"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSettersAndGetters8Bits(t *testing.T) {
t.Parallel()
reg := BuildSSLFSR8(1, 2, 3)
assert.Equal(t, uint8(1), reg.GetRegister())
assert.Equal(t, uint8(2), reg.GetInterval())
assert.Equal(t, uint8(3), reg.GetCounter())
}
func Test8BitShift(t *testing.T) {
t.Parallel()
for i := range math.MaxUint8 + 1 {
reg := NewSSLFSR8(0) // not using interval
reg.register = uint8(i)
for range math.MaxUint8 {
reg.Shift()
}
assert.Equal(t, uint8(i), reg.register, "255 shifts should result in starting state")
}
}
func Test8BitSubShift(t *testing.T) {
t.Parallel()
for i := range math.MaxUint8 + 1 {
reg := NewSSLFSR8(0)
reg.register = uint8(i)
for range math.MaxUint8 {
reg.SubShift()
}
assert.Equal(t, uint8(i), reg.register, "255 subshifts should result in starting state")
}
}
func TestIntervals8Bits(t *testing.T) {
t.Parallel()
intervals := Intervals8Bits()
for _, interval := range intervals {
reg := NewSSLFSR8(uint8(interval))
start := reg.register
reg.Next()
count := 1
for reg.register != start || reg.counter != 0 {
reg.Next()
count++
}
assert.Equal(t, reg.CalculateExpectedMaximalLength(), count)
}
}
func TestNonIntervals8Bits(t *testing.T) {
t.Parallel()
intervals := Intervals8Bits()
for i := 1; i <= math.MaxUint8; i++ {
if slices.Contains(intervals, i) {
continue
}
reg := NewSSLFSR8(uint8(i))
start := reg.register
reg.Next()
count := 1
for reg.register != start || reg.counter != 0 {
reg.Next()
count++
}
assert.NotEqual(t, reg.CalculateExpectedMaximalLength(), count)
}
}