Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions power_of_two_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import (
"github.com/stretchr/testify/assert"
)

const powerOfTwoMessage = "%d should be a power of 2"

func TestIsPowerOf2(t *testing.T) {
// Testing the function
numbers := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1048576, 70368744177664}
for _, num := range numbers {
assert.True(t, IsPowerOfTwo(num), "%d should be a power of 2", num)
assert.True(t, IsPowerOfTwo(num), powerOfTwoMessage, num)
}

numbers = []int{-1, 0, 41, 13}
for _, num := range numbers {
assert.False(t, IsPowerOfTwo(num), "%d should be a power of 2", num)
assert.False(t, IsPowerOfTwo(num), powerOfTwoMessage, num)
}
}

Expand All @@ -25,6 +27,6 @@ func TestNextLowerPowerOf2(t *testing.T) {
expected := []uint{16, 32, 64, 128, 0, 131072}

for i, num := range numbers {
assert.Equal(t, expected[i], NextLowerPowerOfTwo(num), "%d should be a power of 2", num)
assert.Equal(t, expected[i], NextLowerPowerOfTwo(num), powerOfTwoMessage, num)
}
}