summaryrefslogtreecommitdiff
path: root/equals_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'equals_test.go')
-rw-r--r--equals_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/equals_test.go b/equals_test.go
new file mode 100644
index 0000000..93eabb7
--- /dev/null
+++ b/equals_test.go
@@ -0,0 +1,41 @@
+package float
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestEquals(t *testing.T) {
+ testCases := []struct {
+ a, b float64
+ result bool
+ }{
+ {0.0, 0.0, true},
+ {0.0000001, 0.0000001, true},
+ {0.00000011, -0.00000012, true},
+ {-0.00000011, 0.00000012, true},
+ {-0.00000011, -0.00000012, true},
+ {0.0000001, 0.0000002, true},
+ {0.0000002, 0.0000001, true},
+ {0.000002, 0.000001, false},
+ {0.000001, 0.000002, false},
+ {0.00001, 0.00002, false},
+ {0.00002, 0.00001, false},
+ {0.0000101, 0.0000201, false},
+ {0.0000101, 0.0000102, true},
+ }
+ for _, tc := range testCases {
+ name := fmt.Sprintf("%v==%v", tc.a, tc.b)
+ t.Run(name, func(t *testing.T) {
+ if Equals(tc.a, tc.b) != tc.result {
+ t.Fail()
+ }
+ })
+ }
+}
+
+func BenchmarkEquals(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Equals(1.0, 1.0)
+ }
+}