-
Notifications
You must be signed in to change notification settings - Fork 1
/
reverse_rapid_test.go
49 lines (37 loc) · 1.02 KB
/
reverse_rapid_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
package pb_fuzz_workshop
import (
"testing"
"github.com/stretchr/testify/require"
"pgregory.net/rapid"
)
func TestReverseNaive(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
// generate data
s := rapid.SliceOf(rapid.Int()).Draw(t, "slice").([]int)
// run prop.
require.Equal(t, s, Reverse(Reverse(s)))
})
}
func TestReverse(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
s := rapid.SliceOf(rapid.Int()).Draw(t, "slice").([]int)
orig := make([]int, len(s))
require.Equal(t, len(s), copy(orig, s))
reversed := Reverse(s)
for i := range orig {
require.Equal(t, orig[i], reversed[len(orig)-1-i])
}
})
}
func TestReverseGen(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
s := rapid.SliceOf(rapid.Int()).Filter(func(_s []int) bool {
return len(_s) > 0
}).Draw(t, "slice").([]int)
i := rapid.IntRange(0, len(s)-1).Draw(t, "pos").(int)
orig := make([]int, len(s))
require.Equal(t, len(s), copy(orig, s))
reversed := Reverse(s)
require.Equal(t, orig[i], reversed[len(orig)-1-i])
})
}