This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanu_test.go
112 lines (106 loc) · 2.47 KB
/
anu_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package qrng_test
import (
"testing"
"cirello.io/qrng"
)
func TestRead(t *testing.T) {
t.Run("test small", func(t *testing.T) {
buf := make([]byte, 1024)
n, err := qrng.Read(buf)
if err != nil {
t.Fatal("unexpected error found:", err)
} else if n != len(buf) {
t.Fatal("unexpected partial read:", n, len(buf))
}
})
t.Run("test large", func(t *testing.T) {
buf := make([]byte, 2048)
n, err := qrng.Read(buf)
if err != nil {
t.Fatal("unexpected error found:", err)
} else if n != len(buf) {
t.Fatal("unexpected partial read:", n, len(buf))
}
})
}
func TestUint8(t *testing.T) {
type args struct {
length int
}
tests := []struct {
name string
args args
wantErr bool
}{
{"happy case", args{1}, false},
{"too small", args{-1}, true},
{"too large", args{1025}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := qrng.Uint8(tt.args.length)
if (err != nil) != tt.wantErr {
t.Errorf("Uint8() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil && len(got) != tt.args.length {
t.Errorf("Uint8() = %v, want %v", len(got), tt.args.length)
}
})
}
}
func TestUint16(t *testing.T) {
type args struct {
length int
}
tests := []struct {
name string
args args
wantErr bool
}{
{"happy case", args{1}, false},
{"too small", args{-1}, true},
{"too large", args{1025}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := qrng.Uint16(tt.args.length)
if (err != nil) != tt.wantErr {
t.Errorf("Uint16() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil && len(got) != tt.args.length {
t.Errorf("Uint16() = %v, want %v", len(got), tt.args.length)
}
})
}
}
func TestHex16(t *testing.T) {
type args struct {
length int
blockSize int
}
tests := []struct {
name string
args args
wantErr bool
}{
{"happy case", args{1, 1}, false},
{"length too small", args{-1, 1}, true},
{"length too large", args{1025, 1}, true},
{"blockSize too small", args{1, -1}, true},
{"blockSize too large", args{1, 1025}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := qrng.Hex16(tt.args.length, tt.args.blockSize)
if (err != nil) != tt.wantErr {
t.Errorf("Hex16() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err == nil && len(got) != tt.args.length {
t.Errorf("Hex16() = %v, want %v", len(got), tt.args.length)
}
})
}
}