Bug 1318222 - Add a unit test r=sebastian
authorNevin Chen <cnevinchen@gmail.com>
Thu, 17 Nov 2016 14:44:10 +0800
changeset 324389 16b1dec1956fb81cada13fe80cf0c005b2a755e0
parent 324388 b435f6479aa02a089d664b4800c6eff77c08ac46
child 324390 5aa4b8d980786d55d1fda696329312f40cc33868
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerssebastian
bugs1318222
milestone53.0a1
Bug 1318222 - Add a unit test r=sebastian MozReview-Commit-ID: Fv1e2dtPKut
mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFloatUtils.java
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFloatUtils.java
@@ -0,0 +1,68 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+package org.mozilla.gecko.util;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mozilla.gecko.background.testhelpers.TestRunner;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Unit tests for float utilities.
+ */
+@RunWith(TestRunner.class)
+public class TestFloatUtils {
+    @Test
+    public void testZeros() {
+        assertTrue(FloatUtils.fuzzyEquals(0, 0));
+    }
+
+    @Test
+    public void testNotEqual() {
+        assertFalse(FloatUtils.fuzzyEquals(10, 0));
+    }
+
+    @Test
+    public void testEqualsPromoted() {
+        assertTrue(FloatUtils.fuzzyEquals(5, 5));
+    }
+
+    @Test
+    public void testEqualsUnPromoted() {
+        assertTrue(FloatUtils.fuzzyEquals(5.6f, 5.6f));
+    }
+
+    @Test
+    public void testClampSuccess() {
+        assertTrue(3 == FloatUtils.clamp(3, 1, 5));
+    }
+
+    @Test
+    public void testClampFail() {
+        try {
+            FloatUtils.clamp(3, 5, 1);
+        } catch (IllegalArgumentException e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void testInterpolateSuccess() {
+        assertTrue(4 == FloatUtils.interpolate(1, 2, 3));
+    }
+
+    @Test
+    public void testInterpolateFail() {
+        assertFalse(3 == FloatUtils.interpolate(1, 2, 3));
+    }
+
+
+}