@@ -22,100 +22,152 @@ import (
22
22
23
23
func TestGrowthGrowing (t * testing.T ) {
24
24
t .Parallel ()
25
- initialSize := 1
26
- g := NewTypedRingGrowing [int ](RingGrowingOptions {InitialSize : initialSize })
27
-
28
- if expected , actual := 0 , g .Len (); expected != actual {
29
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
30
- }
31
- if expected , actual := initialSize , g .Cap (); expected != actual {
32
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
33
- }
34
-
35
- x := 10
36
- for i := 0 ; i < x ; i ++ {
37
- if e , a := i , g .readable ; e != a {
38
- t .Fatalf ("expected equal, got %#v, %#v" , e , a )
39
- }
40
- g .WriteOne (i )
25
+ tests := map [string ]struct {
26
+ ring * TypedRingGrowing [int ]
27
+ initialSize int
28
+ }{
29
+ "implicit-zero" : {
30
+ ring : new (TypedRingGrowing [int ]),
31
+ },
32
+ "explicit-zero" : {
33
+ ring : NewTypedRingGrowing [int ](RingGrowingOptions {InitialSize : 0 }),
34
+ initialSize : 0 ,
35
+ },
36
+ "nonzero" : {
37
+ ring : NewTypedRingGrowing [int ](RingGrowingOptions {InitialSize : 1 }),
38
+ initialSize : 1 ,
39
+ },
40
+ }
41
+
42
+ for name , test := range tests {
43
+ t .Run (name , func (t * testing.T ) {
44
+ initialSize := test .initialSize
45
+ g := test .ring
46
+
47
+ if expected , actual := 0 , g .Len (); expected != actual {
48
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
49
+ }
50
+ if expected , actual := initialSize , g .Cap (); expected != actual {
51
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
52
+ }
53
+
54
+ x := 10
55
+ for i := 0 ; i < x ; i ++ {
56
+ if e , a := i , g .readable ; e != a {
57
+ t .Fatalf ("expected equal, got %#v, %#v" , e , a )
58
+ }
59
+ g .WriteOne (i )
60
+ }
61
+
62
+ if expected , actual := x , g .Len (); expected != actual {
63
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
64
+ }
65
+ if expected , actual := 16 , g .Cap (); expected != actual {
66
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
67
+ }
68
+
69
+ read := 0
70
+ for g .readable > 0 {
71
+ v , ok := g .ReadOne ()
72
+ if ! ok {
73
+ t .Fatal ("expected true" )
74
+ }
75
+ if read != v {
76
+ t .Fatalf ("expected %#v==%#v" , read , v )
77
+ }
78
+ read ++
79
+ }
80
+ if x != read {
81
+ t .Fatalf ("expected to have read %d items: %d" , x , read )
82
+ }
83
+ if expected , actual := 0 , g .Len (); expected != actual {
84
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
85
+ }
86
+ if expected , actual := 16 , g .Cap (); expected != actual {
87
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
88
+ }
89
+ })
41
90
}
42
91
43
- if expected , actual := x , g .Len (); expected != actual {
44
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
45
- }
46
- if expected , actual := 16 , g .Cap (); expected != actual {
47
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
48
- }
49
-
50
- read := 0
51
- for g .readable > 0 {
52
- v , ok := g .ReadOne ()
53
- if ! ok {
54
- t .Fatal ("expected true" )
55
- }
56
- if read != v {
57
- t .Fatalf ("expected %#v==%#v" , read , v )
58
- }
59
- read ++
60
- }
61
- if x != read {
62
- t .Fatalf ("expected to have read %d items: %d" , x , read )
63
- }
64
- if expected , actual := 0 , g .Len (); expected != actual {
65
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
66
- }
67
- if expected , actual := 16 , g .Cap (); expected != actual {
68
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
69
- }
70
92
}
71
93
72
94
func TestGrowth (t * testing.T ) {
73
95
t .Parallel ()
74
- initialSize := 1
75
- normalSize := 2
76
- g := NewRing [int ](RingOptions {InitialSize : initialSize , NormalSize : normalSize })
77
96
78
- if expected , actual := 0 , g .Len (); expected != actual {
79
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
80
- }
81
- if expected , actual := initialSize , g .Cap (); expected != actual {
82
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
83
- }
84
-
85
- x := 10
86
- for i := 0 ; i < x ; i ++ {
87
- if e , a := i , g .growing .readable ; e != a {
88
- t .Fatalf ("expected equal, got %#v, %#v" , e , a )
89
- }
90
- g .WriteOne (i )
91
- }
92
-
93
- if expected , actual := x , g .Len (); expected != actual {
94
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
95
- }
96
- if expected , actual := 16 , g .Cap (); expected != actual {
97
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
98
- }
99
-
100
- read := 0
101
- for g .growing .readable > 0 {
102
- v , ok := g .ReadOne ()
103
- if ! ok {
104
- t .Fatal ("expected true" )
105
- }
106
- if read != v {
107
- t .Fatalf ("expected %#v==%#v" , read , v )
108
- }
109
- read ++
110
- }
111
- if x != read {
112
- t .Fatalf ("expected to have read %d items: %d" , x , read )
113
- }
114
- if expected , actual := 0 , g .Len (); expected != actual {
115
- t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
116
- }
117
- if expected , actual := normalSize , g .Cap (); expected != actual {
118
- t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
97
+ tests := map [string ]struct {
98
+ ring * Ring [int ]
99
+ initialSize int
100
+ normalSize int
101
+ }{
102
+ "implicit-zero" : {
103
+ ring : new (Ring [int ]),
104
+ },
105
+ "explicit-zero" : {
106
+ ring : NewRing [int ](RingOptions {InitialSize : 0 , NormalSize : 0 }),
107
+ initialSize : 0 ,
108
+ normalSize : 0 ,
109
+ },
110
+ "smaller-initial-size" : {
111
+ ring : NewRing [int ](RingOptions {InitialSize : 1 , NormalSize : 2 }),
112
+ initialSize : 1 ,
113
+ normalSize : 2 ,
114
+ },
115
+ "smaller-normal-size" : {
116
+ ring : NewRing [int ](RingOptions {InitialSize : 2 , NormalSize : 1 }),
117
+ initialSize : 2 ,
118
+ normalSize : 1 ,
119
+ },
120
+ }
121
+
122
+ for name , test := range tests {
123
+ t .Run (name , func (t * testing.T ) {
124
+ initialSize := test .initialSize
125
+ normalSize := test .normalSize
126
+ g := test .ring
127
+
128
+ if expected , actual := 0 , g .Len (); expected != actual {
129
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
130
+ }
131
+ if expected , actual := initialSize , g .Cap (); expected != actual {
132
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
133
+ }
134
+
135
+ x := 10
136
+ for i := 0 ; i < x ; i ++ {
137
+ if e , a := i , g .growing .readable ; e != a {
138
+ t .Fatalf ("expected equal, got %#v, %#v" , e , a )
139
+ }
140
+ g .WriteOne (i )
141
+ }
142
+
143
+ if expected , actual := x , g .Len (); expected != actual {
144
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
145
+ }
146
+ if expected , actual := 16 , g .Cap (); expected != actual {
147
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
148
+ }
149
+
150
+ read := 0
151
+ for g .growing .readable > 0 {
152
+ v , ok := g .ReadOne ()
153
+ if ! ok {
154
+ t .Fatal ("expected true" )
155
+ }
156
+ if read != v {
157
+ t .Fatalf ("expected %#v==%#v" , read , v )
158
+ }
159
+ read ++
160
+ }
161
+ if x != read {
162
+ t .Fatalf ("expected to have read %d items: %d" , x , read )
163
+ }
164
+ if expected , actual := 0 , g .Len (); expected != actual {
165
+ t .Fatalf ("expected Len to be %d, got %d" , expected , actual )
166
+ }
167
+ if expected , actual := normalSize , g .Cap (); expected != actual {
168
+ t .Fatalf ("expected Cap to be %d, got %d" , expected , actual )
169
+ }
170
+ })
119
171
}
120
172
}
121
173
0 commit comments