@@ -6,16 +6,18 @@ import (
66 "github.com/stretchr/testify/assert"
77)
88
9+ const powerOfTwoMessage = "%d should be a power of 2"
10+
911func TestIsPowerOf2 (t * testing.T ) {
1012 // Testing the function
1113 numbers := []int {1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 , 1048576 , 70368744177664 }
1214 for _ , num := range numbers {
13- assert .True (t , IsPowerOfTwo (num ), "%d should be a power of 2" , num )
15+ assert .True (t , IsPowerOfTwo (num ), powerOfTwoMessage , num )
1416 }
1517
1618 numbers = []int {- 1 , 0 , 41 , 13 }
1719 for _ , num := range numbers {
18- assert .False (t , IsPowerOfTwo (num ), "%d should be a power of 2" , num )
20+ assert .False (t , IsPowerOfTwo (num ), powerOfTwoMessage , num )
1921 }
2022}
2123
@@ -25,6 +27,6 @@ func TestNextLowerPowerOf2(t *testing.T) {
2527 expected := []uint {16 , 32 , 64 , 128 , 0 , 131072 }
2628
2729 for i , num := range numbers {
28- assert .Equal (t , expected [i ], NextLowerPowerOfTwo (num ), "%d should be a power of 2" , num )
30+ assert .Equal (t , expected [i ], NextLowerPowerOfTwo (num ), powerOfTwoMessage , num )
2931 }
3032}
0 commit comments