Skip to content

Commit 5356260

Browse files
authored
Merge pull request #430 from Park-Jiyeonn/fix/hasTwoOrMoreTrue
Fix incorrect logic in `hasTwoOrMoreTrue` function
2 parents fc70a10 + 804bf2a commit 5356260

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

simulator/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ func GetKubeClientConfig() (*rest.Config, error) {
333333
func hasTwoOrMoreTrue(values ...bool) bool {
334334
trueExist := false
335335
for _, v := range values {
336-
if trueExist {
336+
if trueExist && v {
337337
return true
338338
}
339-
trueExist = v
339+
trueExist = trueExist || v
340340
}
341341
return false
342342
}

simulator/config/config_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,59 @@ func Test_validateURLs(t *testing.T) {
195195
})
196196
}
197197
}
198+
199+
func Test_hasTwoOrMoreTrue(t *testing.T) {
200+
t.Parallel()
201+
tests := []struct {
202+
name string
203+
input []bool
204+
expected bool
205+
}{
206+
{
207+
name: "No true values",
208+
input: []bool{false, false, false},
209+
expected: false,
210+
},
211+
{
212+
name: "One true value",
213+
input: []bool{false, true, false},
214+
expected: false,
215+
},
216+
{
217+
name: "Two true values",
218+
input: []bool{true, false, true},
219+
expected: true,
220+
},
221+
{
222+
name: "Three true values",
223+
input: []bool{true, true, true},
224+
expected: true,
225+
},
226+
{
227+
name: "Empty input",
228+
input: []bool{},
229+
expected: false,
230+
},
231+
{
232+
name: "Two trues at start",
233+
input: []bool{true, true, false},
234+
expected: true,
235+
},
236+
{
237+
name: "Two trues at end",
238+
input: []bool{false, false, true, true},
239+
expected: true,
240+
},
241+
}
242+
243+
for _, tt := range tests {
244+
tt := tt
245+
t.Run(tt.name, func(t *testing.T) {
246+
t.Parallel()
247+
result := hasTwoOrMoreTrue(tt.input...)
248+
if result != tt.expected {
249+
t.Errorf("hasTwoOrMoreTrue(%v) = %v; want %v", tt.input, result, tt.expected)
250+
}
251+
})
252+
}
253+
}

0 commit comments

Comments
 (0)