-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex128Slices_test.go
104 lines (97 loc) · 3.84 KB
/
complex128Slices_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
// Code generated by yasupGen; DO NOT EDIT.
package yasup_test
import (
yasup "github.com/j4rv/yasup"
"testing"
)
func Test_Complex128Insert(t *testing.T) {
type testCase struct {
name string
slice []complex128
insertAt int
}
base := []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}
tcs := []testCase{
{"First", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, 0},
{"Middle", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, len(base) / 2},
{"Last", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, len(base)},
{"Empty slice", []complex128{}, 0},
{"Nil slice", nil, 0},
}
for _, tc := range tcs {
yasup.Complex128Insert(&tc.slice, -52.6084+155.80287i, tc.insertAt)
if tc.slice[tc.insertAt] != (-52.6084 + 155.80287i) {
t.Error(tc)
}
}
}
func Test_Complex128FastShuffle(t *testing.T) {
shuffles := [][]complex128{}
for i := 0; i < 8; i++ {
or := []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}
yasup.Complex128FastShuffle(or)
shuffles = append(shuffles, or)
}
for i := range shuffles {
for j := range shuffles {
if i >= j {
continue
}
if yasup.Complex128Equals(shuffles[i], shuffles[j]) {
// If there is any collision in 8 shuffles, the Shuffle function is probably broken
t.Fail()
}
}
}
// check that nil does not panic
yasup.Complex128FastShuffle(nil)
}
func Test_Complex128SecureShuffle(t *testing.T) {
shuffles := [][]complex128{}
for i := 0; i < 8; i++ {
or := []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}
yasup.Complex128SecureShuffle(or)
shuffles = append(shuffles, or)
}
for i := range shuffles {
for j := range shuffles {
if i >= j {
continue
}
if yasup.Complex128Equals(shuffles[i], shuffles[j]) {
// If there is any collision in 8 shuffles, the Shuffle function is probably broken
t.Fail()
}
}
}
// check that nil does not panic
yasup.Complex128SecureShuffle(nil)
}
func Test_Complex128Equals(t *testing.T) {
type TestCase struct {
name string
a, b []complex128
exp bool
}
tcs := []TestCase{
// nil checks
{"Equals nil", nil, nil, true},
// golang treats empty and nil slices as the same thing in most cases, we'll do the same
{"Left nil, right empty", nil, []complex128{}, true},
{"Right nil, left empty", []complex128{}, nil, true},
{"Left nil, right not empty", nil, []complex128{-52.6084 + 155.80287i}, false},
{"Right nil, left not empty", []complex128{-52.6084 + 155.80287i}, nil, false},
{"Equals empty", []complex128{}, []complex128{}, true},
{"Equals 1", []complex128{-52.6084 + 155.80287i}, []complex128{-52.6084 + 155.80287i}, true},
{"Equals 2", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, true},
{"Not equals 1", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i, -52.6084 + 155.80287i}, false},
{"Not equals 2", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, []complex128{}, false},
{"Not equals 3", []complex128{0 + 0i, 1 + 2i, -2 + 7.5i, 3 + 42.1i, 4 - 74.6i, -5 + 4i, 6 - 88i, 7 - 0i, 8 + 100i, 9 + 99i}, []complex128{-52.6084 + 155.80287i, -52.6084 + 155.80287i}, false},
}
for _, tc := range tcs {
got := yasup.Complex128Equals(tc.a, tc.b)
if got != tc.exp {
t.Error(tc)
}
}
}