From 7c3adfba29d6d1160602e7c434fc57c7af35876e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 26 Sep 2016 10:25:08 +0200 Subject: [PATCH] Add benchmark for ToBool ``` BenchmarkTooBool-4 500000 2781 ns/op 49 B/op 3 allocs/op ``` --- cast_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cast_test.go b/cast_test.go index 8f6d40b..6b73ff8 100644 --- a/cast_test.go +++ b/cast_test.go @@ -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) { @@ -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