]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixed flaky min/max test
authorIskren Chernev <iskren.chernev@gmail.com>
Sat, 14 Sep 2013 07:52:29 +0000 (00:52 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sat, 14 Sep 2013 07:52:29 +0000 (00:52 -0700)
test/moment/min_max.js

index 319a4f47869e447167609f76bc8c59929a9deccd..133ef67bb037425e723996808400791810165cf2 100644 (file)
@@ -1,5 +1,9 @@
 var moment = require("../../moment");
 
+var equalMoment = function(test, a, b, msg) {
+    test.equal(a.valueOf(), b.valueOf(), msg);
+};
+
 exports.min_max = {
     setUp : function (cb) {
         moment.lang('en');
@@ -12,51 +16,39 @@ exports.min_max = {
     },
 
     "min" : function (test) {
-        test.expect(8);
+        test.expect(6);
 
         var now = moment(),
             future = now.clone().add(1, 'month'),
-            past = now.clone().subtract(1, 'month'),
-            eps = 10;
+            past = now.clone().subtract(1, 'month');
 
-        // we use Math.abs(a.diff(b)) < eps to prevent issues where
-        // two moments are off by a millisecond.
+        equalMoment(test, past.min(now), now,       "A past date with the minimum of now should be now");
+        equalMoment(test, past.min(future), future, "A past date with the minimum of the future should be the future date");
 
-        test.ok(Math.abs(past.min(now).diff(now)) < eps,        "A past date with the minimum of now should be now");
-        test.ok(Math.abs(past.min().diff(now)) < eps,           "A past date with the minimum of implied now should be now");
-        test.ok(Math.abs(past.min(future).diff(future)) < eps,  "A past date with the minimum of the future should be the future date");
+        equalMoment(test, future.min(now), future,  "A future date with the minimum of now should be the future");
+        equalMoment(test, future.min(past), future, "A future date with the minimum of the past should be the future");
 
-        test.ok(Math.abs(future.min(now).diff(future)) < eps,   "A future date with the minimum of now should be the future");
-        test.ok(Math.abs(future.min().diff(future)) < eps,      "A future date with the minimum of implied now should be the future");
-        test.ok(Math.abs(future.min(past).diff(future)) < eps,  "A future date with the minimum of the past should be the future");
-
-        test.ok(Math.abs(now.min(past).diff(now)) < eps,        "Now with the minimum of the past should be now");
-        test.ok(Math.abs(now.min(future).diff(future)) < eps,   "Now with the minimum of the future should be the future");
+        equalMoment(test, now.min(past), now,       "Now with the minimum of the past should be now");
+        equalMoment(test, now.min(future), future,  "Now with the minimum of the future should be the future");
 
         test.done();
     },
 
     "max" : function (test) {
-        test.expect(8);
+        test.expect(6);
 
         var now = moment(),
             future = now.clone().add(1, 'month'),
-            past = now.clone().subtract(1, 'month'),
-            eps = 10;
-
-        // we use Math.abs(a.diff(b)) < eps to prevent issues where
-        // two moments are off by a millisecond.
+            past = now.clone().subtract(1, 'month');
 
-        test.ok(Math.abs(past.max(now).diff(past)) < eps,    "A past date with the maximum of now should be the past");
-        test.ok(Math.abs(past.max().diff(past)) < eps,       "A past date with the maximum of implied now should be the past");
-        test.ok(Math.abs(past.max(future).diff(past)) < eps, "A past date with the maximum of the future should be the past");
+        equalMoment(test, past.max(now), past,    "A past date with the maximum of now should be the past");
+        equalMoment(test, past.max(future), past, "A past date with the maximum of the future should be the past");
 
-        test.ok(Math.abs(future.max(now).diff(now)) < eps,   "A future date with the maximum of now should be now");
-        test.ok(Math.abs(future.max().diff(now)) < eps,      "A future date with the maximum of implied now should be now");
-        test.ok(Math.abs(future.max(past).diff(past)) < eps, "A future date with the maximum of the past should be the past");
+        equalMoment(test, future.max(now), now,   "A future date with the maximum of now should be now");
+        equalMoment(test, future.max(past), past, "A future date with the maximum of the past should be the past");
 
-        test.ok(Math.abs(now.max(past).diff(past)) < eps,    "Now with the maximum of the past should be the past");
-        test.ok(Math.abs(now.max(future).diff(now)) < eps,   "Now with the maximum of the future should be now");
+        equalMoment(test, now.max(past), past,    "Now with the maximum of the past should be the past");
+        equalMoment(test, now.max(future), now,   "Now with the maximum of the future should be now");
 
         test.done();
     }