Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsaygelle committed Oct 18, 2023
1 parent ec4e51d commit 8e8c9ff
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions hashtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,14 @@ func TestEachKeyBreak(t *testing.T) {
ht["banana"] = 3
ht["cherry"] = 8

// Define a function to print each key and break if the key is "banana".
var printedKeys []string
printAndBreak := func(key string) bool {
printedKeys = append(printedKeys, key)
return key == "banana"
}

// Iterate over the keys and print each key, breaking if the key is "banana".
ht.EachKeyBreak(printAndBreak)

// Sort the printed values for consistent comparison.
sort.Strings(printedKeys)
var keyToBreak string
ht.EachBreak(func(key string, value int) bool {
keyToBreak = key
return key != "banana"
})

for i, key := range printedKeys {
if key == "banana" {
t.Fatalf("Unexpected value %d at index %s", i, key)
}
if keyToBreak != "banana" {
t.Fatalf("Expect keyToBreak to equal 'banana', but got %s", keyToBreak)
}
}

Expand Down

0 comments on commit 8e8c9ff

Please sign in to comment.