Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: common/cmpbin/float_test.go

Issue 1219323002: Rename funnybase and add more serializations. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fixes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/cmpbin/float.go ('k') | common/cmpbin/number.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/cmpbin/float_test.go
diff --git a/common/cmpbin/float_test.go b/common/cmpbin/float_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..903e0e15e073b8c47d53f11f99f9c02cdf0bc6a5
--- /dev/null
+++ b/common/cmpbin/float_test.go
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package cmpbin
+
+import (
+ "bytes"
+ "io"
+ "math/rand"
+ "sort"
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestFloats(t *testing.T) {
+ t.Parallel()
+
+ Convey("floats", t, func() {
+ b := &bytes.Buffer{}
+
+ Convey("good", func() {
+ f1 := float64(1.234)
+ n, err := WriteFloat64(b, f1)
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 8)
+ f, n, err := ReadFloat64(b)
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 8)
+ So(f, ShouldEqual, f1)
+ })
+
+ Convey("bad", func() {
+ _, n, err := ReadFloat64(b)
+ So(err, ShouldEqual, io.EOF)
+ So(n, ShouldEqual, 0)
+ })
+ })
+}
+
+func TestFloatSortability(t *testing.T) {
+ t.Parallel()
+
+ Convey("floats maintain sort order", t, func() {
+ vec := make(sort.Float64Slice, randomTestSize)
+ r := rand.New(rand.NewSource(*seed))
+ for i := range vec {
+ vec[i] = r.Float64()
+ }
+
+ bin := make(sort.StringSlice, len(vec))
+ b := &bytes.Buffer{}
+ for i := range bin {
+ b.Reset()
+ n, err := WriteFloat64(b, vec[i])
+ So(err, ShouldBeNil)
+ So(n, ShouldEqual, 8)
+ bin[i] = b.String()
+ }
+
+ vec.Sort()
+ bin.Sort()
+
+ for i := range vec {
+ r, _, err := ReadFloat64(bytes.NewBufferString(bin[i]))
+ So(err, ShouldBeNil)
+ So(vec[i], ShouldEqual, r)
+ }
+ })
+}
« no previous file with comments | « common/cmpbin/float.go ('k') | common/cmpbin/number.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698