summaryrefslogtreecommitdiff
path: root/round_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'round_test.go')
-rw-r--r--round_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/round_test.go b/round_test.go
new file mode 100644
index 0000000..adabd96
--- /dev/null
+++ b/round_test.go
@@ -0,0 +1,38 @@
+package float
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestRound(t *testing.T) {
+ testCases := []struct {
+ in, out float64
+ }{
+ {0.0, 0.0},
+ {0.3, 0.3},
+ {0.333, 0.33},
+ {0.334, 0.33},
+ {0.335, 0.34},
+ {-0.333, -0.33},
+ {-0.334, -0.33},
+ {-0.335, -0.34},
+ {495.17999999999995, 495.18},
+ {-495.17999999999995, -495.18},
+ {0.115, 0.12},
+ {-0.115, -0.12},
+ }
+ for _, tc := range testCases {
+ t.Run(fmt.Sprint(tc.in), func(t *testing.T) {
+ if r := Round(tc.in); r != tc.out {
+ t.Errorf("got %v, want %v", r, tc.out)
+ }
+ })
+ }
+}
+
+func BenchmarkRound(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Round(0.333)
+ }
+}