Skip to content

Commit

Permalink
Add benchmark for ToBool
Browse files Browse the repository at this point in the history
```
BenchmarkTooBool-4   	  500000	      2781 ns/op	      49 B/op	       3 allocs/op
```
  • Loading branch information
bep committed Sep 26, 2016
1 parent 60e7a69 commit 7c3adfb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func TestSlices(t *testing.T) {
assert.Equal(t, []int{2, 3}, ToIntSlice([2]string{"2", "3"}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]bool{true, false, true}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]interface{}{true, false, true}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]int{1,0,1}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]string{"true","false","true"}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]int{1, 0, 1}))
assert.Equal(t, []bool{true, false, true}, ToBoolSlice([]string{"true", "false", "true"}))
}

func TestToBool(t *testing.T) {
Expand All @@ -168,6 +168,14 @@ func TestToBool(t *testing.T) {
assert.Equal(t, ToBool(-1), true)
}

func BenchmarkTooBool(b *testing.B) {
for i := 0; i < b.N; i++ {
if !ToBool(true) {
b.Fatal("ToBool returned false")
}
}
}

func TestIndirectPointers(t *testing.T) {
x := 13
y := &x
Expand Down

0 comments on commit 7c3adfb

Please sign in to comment.