diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
commit | 758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch) | |
tree | 6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/expvar/expvar_test.go | |
parent | 3e45412327a2654a77944249962b3652e6142299 (diff) | |
download | golang-upstream/2011-02-01.1.tar.gz |
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/expvar/expvar_test.go')
-rw-r--r-- | src/pkg/expvar/expvar_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pkg/expvar/expvar_test.go b/src/pkg/expvar/expvar_test.go index 009f24d1a..a8b1a96a9 100644 --- a/src/pkg/expvar/expvar_test.go +++ b/src/pkg/expvar/expvar_test.go @@ -34,6 +34,31 @@ func TestInt(t *testing.T) { } } +func TestFloat(t *testing.T) { + reqs := NewFloat("requests-float") + if reqs.f != 0.0 { + t.Errorf("reqs.f = %v, want 0", reqs.f) + } + if reqs != Get("requests-float").(*Float) { + t.Errorf("Get() failed.") + } + + reqs.Add(1.5) + reqs.Add(1.25) + if reqs.f != 2.75 { + t.Errorf("reqs.f = %v, want 2.75", reqs.f) + } + + if s := reqs.String(); s != "2.75" { + t.Errorf("reqs.String() = %q, want \"4.64\"", s) + } + + reqs.Add(-2) + if reqs.f != 0.75 { + t.Errorf("reqs.f = %v, want 0.75", reqs.f) + } +} + func TestString(t *testing.T) { name := NewString("my-name") if name.s != "" { @@ -56,12 +81,16 @@ func TestMapCounter(t *testing.T) { colours.Add("red", 1) colours.Add("red", 2) colours.Add("blue", 4) + colours.AddFloat("green", 4.125) if x := colours.m["red"].(*Int).i; x != 3 { t.Errorf("colours.m[\"red\"] = %v, want 3", x) } if x := colours.m["blue"].(*Int).i; x != 4 { t.Errorf("colours.m[\"blue\"] = %v, want 4", x) } + if x := colours.m["green"].(*Float).f; x != 4.125 { + t.Errorf("colours.m[\"green\"] = %v, want 3.14", x) + } // colours.String() should be '{"red":3, "blue":4}', // though the order of red and blue could vary. @@ -98,6 +127,19 @@ func TestIntFunc(t *testing.T) { } } +func TestFloatFunc(t *testing.T) { + x := 8.5 + ix := FloatFunc(func() float64 { return x }) + if s := ix.String(); s != "8.5" { + t.Errorf("ix.String() = %v, want 3.14", s) + } + + x -= 1.25 + if s := ix.String(); s != "7.25" { + t.Errorf("ix.String() = %v, want 4.34", s) + } +} + func TestStringFunc(t *testing.T) { x := "hello" sx := StringFunc(func() string { return x }) |