...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package generic
17
18 import (
19 "testing"
20
21 . "github.com/onsi/gomega"
22 )
23
24 func TestRandomFixedIndexes(t *testing.T) {
25 g := NewGomegaWithT(t)
26
27 type TestCase struct {
28 name string
29 start uint
30 end uint
31 count uint
32 expectedOutputLen int
33 }
34
35 tcs := []TestCase{
36 {
37 name: "start 0, end 10, count 3",
38 start: 0,
39 end: 10,
40 count: 3,
41 expectedOutputLen: 3,
42 },
43 {
44 name: "start 0, end 10, count 12",
45 start: 0,
46 end: 10,
47 count: 12,
48 expectedOutputLen: 10,
49 },
50 {
51 name: "start 5, end 10, count 3",
52 start: 5,
53 end: 10,
54 count: 3,
55 expectedOutputLen: 3,
56 },
57 }
58
59 for _, tc := range tcs {
60 values := RandomFixedIndexes(tc.start, tc.end, tc.count)
61 g.Expect(len(values)).To(Equal(tc.expectedOutputLen), tc.name)
62
63 for _, v := range values {
64 g.Expect(v).Should(BeNumerically(">=", tc.start), tc.name)
65 g.Expect(v).Should(BeNumerically("<", tc.end), tc.name)
66 }
67 }
68 }
69