From 64a507e2f19fc1ed9dab7f8123b334067d107533 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 21 May 2017 15:02:35 +0200 Subject: initial import --- equals_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 equals_test.go (limited to 'equals_test.go') 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) + } +} -- cgit v1.2.3