Bug 1318222 - Updated the unit test,added more test r?sebastian draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 17 Nov 2016 16:29:23 +0800
changeset 441020 0b4b23186487e0f46f575553ceea9a6a03f271fe
parent 441019 95844a34768fd91098a8286dbab92976fd3bbc90
child 441021 9acb13c266a2ace9b539f7698f6ca62171edc4db
push id36330
push userbmo:cnevinchen@gmail.com
push dateFri, 18 Nov 2016 07:07:03 +0000
reviewerssebastian
bugs1318222
milestone52.0a1
Bug 1318222 - Updated the unit test,added more test r?sebastian MozReview-Commit-ID: 8PvSoPJQ88n
mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFloatUtils.java
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFloatUtils.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFloatUtils.java
@@ -5,64 +5,72 @@
  */
 
 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.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
 
 /**
  * Unit tests for float utilities.
  */
 @RunWith(TestRunner.class)
 public class TestFloatUtils {
+
     @Test
-    public void testZeros() {
+    public void testEqualIfComparingZeros() {
         assertTrue(FloatUtils.fuzzyEquals(0, 0));
     }
 
     @Test
-    public void testNotEqual() {
+    public void testEqualFailIf5thDigitIsDifferent() {
+        assertFalse(FloatUtils.fuzzyEquals(0.00001f, 0.00002f));
+    }
+
+    @Test
+    public void testEqualSuccessIf6thDigitIsDifferent() {
+        assertTrue(FloatUtils.fuzzyEquals(0.000001f, 0.000002f));
+    }
+
+    @Test
+    public void testEqualFail() {
         assertFalse(FloatUtils.fuzzyEquals(10, 0));
     }
 
     @Test
-    public void testEqualsPromoted() {
+    public void testEqualSuccessIfPromoted() {
         assertTrue(FloatUtils.fuzzyEquals(5, 5));
     }
 
     @Test
-    public void testEqualsUnPromoted() {
+    public void testEqualSuccessIfUnPromoted() {
         assertTrue(FloatUtils.fuzzyEquals(5.6f, 5.6f));
     }
 
     @Test
     public void testClampSuccess() {
-        assertTrue(3 == FloatUtils.clamp(3, 1, 5));
+        assertEquals(3, FloatUtils.clamp(3, 1, 5), 0);
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testClampFail() {
-        try {
-            FloatUtils.clamp(3, 5, 1);
-        } catch (IllegalArgumentException e) {
-            assertNotNull(e);
-        }
+        FloatUtils.clamp(3, 5, 1);
     }
 
     @Test
     public void testInterpolateSuccess() {
-        assertTrue(4 == FloatUtils.interpolate(1, 2, 3));
+        assertEquals(4f ,FloatUtils.interpolate(1, 2, 3), 0f);
     }
 
     @Test
     public void testInterpolateFail() {
-        assertFalse(3 == FloatUtils.interpolate(1, 2, 3));
+        assertNotEquals(3f ,FloatUtils.interpolate(1, 2, 3), 0f);
     }
 
 
 }