Skip to content

Commit

Permalink
Restore GetBool benchmarks
Browse files Browse the repository at this point in the history
Disappeared during rebase
  • Loading branch information
benoitmasson committed Sep 29, 2016
1 parent 3b8c1c9 commit 892b80c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,3 +938,40 @@ func TestDotParameter(t *testing.T) {
expected := []interface{}{map[string]interface{}{"type": "Small"}}
assert.Equal(t, expected, actual)
}

func TestGetBool(t *testing.T) {
key := "BooleanKey"
v = New()
v.Set(key, true)
if !v.GetBool(key) {
t.Fatal("GetBool returned false")
}
if v.GetBool("NotFound") {
t.Fatal("GetBool returned true")
}
}

func BenchmarkGetBool(b *testing.B) {
key := "BenchmarkGetBool"
v = New()
v.Set(key, true)

for i := 0; i < b.N; i++ {
if !v.GetBool(key) {
b.Fatal("GetBool returned false")
}
}
}

// This is the "perfect result" for the above.
func BenchmarkGetBoolFromMap(b *testing.B) {
m := make(map[string]bool)
key := "BenchmarkGetBool"
m[key] = true

for i := 0; i < b.N; i++ {
if !m[key] {
b.Fatal("Map value was false")
}
}
}

0 comments on commit 892b80c

Please sign in to comment.