From ab77d9d83a80ae43e3a9682e557856b2f1896152 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 20 Mar 2016 10:16:03 -0700 Subject: [PATCH] Add more math operation method tests. --- test/test.js | 78 ++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 52 deletions(-) diff --git a/test/test.js b/test/test.js index f459d2d81..60018f1f0 100644 --- a/test/test.js +++ b/test/test.js @@ -1046,48 +1046,12 @@ assert.strictEqual(_.add(-6, -4), -10); }); - QUnit.test('should return `0` when no arguments are given', function(assert) { - assert.expect(1); - - assert.strictEqual(_.add(), 0); - }); - QUnit.test('should not coerce arguments to numbers', function(assert) { assert.expect(2); assert.strictEqual(_.add('6', '4'), '64'); assert.strictEqual(_.add('x', 'y'), 'xy'); }); - - QUnit.test('should work with only an `augend` or `addend`', function(assert) { - assert.expect(3); - - assert.strictEqual(_.add(6), 6); - assert.strictEqual(_.add(6, undefined), 6); - assert.strictEqual(_.add(undefined, 4), 4); - }); - - QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) { - assert.expect(1); - - if (!isNpm) { - assert.strictEqual(_(1).add(2), 3); - } - else { - skipAssert(assert); - } - }); - - QUnit.test('should return a wrapped value when explicitly chaining', function(assert) { - assert.expect(1); - - if (!isNpm) { - assert.ok(_(1).chain().add(2) instanceof _); - } - else { - skipAssert(assert); - } - }); }()); /*--------------------------------------------------------------------------*/ @@ -19951,49 +19915,59 @@ assert.strictEqual(_.subtract(-6, -4), -2); }); - QUnit.test('should return `0` when no arguments are given', function(assert) { - assert.expect(1); - - assert.strictEqual(_.subtract(), 0); - }); - - QUnit.test('should coerce arguments only numbers', function(assert) { + QUnit.test('should coerce arguments to numbers', function(assert) { assert.expect(2); assert.strictEqual(_.subtract('6', '4'), 2); assert.deepEqual(_.subtract('x', 'y'), NaN); }); + }()); - QUnit.test('should work with only a `minuend` or `subtrahend`', function(assert) { + /*--------------------------------------------------------------------------*/ + + QUnit.module('math operator methods'); + + lodashStable.each(['add', 'divide', 'multiply', 'subtract'], function(methodName) { + var func = _[methodName]; + + QUnit.test('`_.' + methodName + '` should return `0` when no arguments are given', function(assert) { + assert.expect(1); + + assert.strictEqual(func(), 0); + }); + + QUnit.test('`_.' + methodName + '` should work with only one defined argument', function(assert) { assert.expect(3); - assert.strictEqual(_.subtract(6), 6); - assert.strictEqual(_.subtract(6, undefined), 6); - assert.strictEqual(_.subtract(undefined, 4), 4); + assert.strictEqual(func(6), 6); + assert.strictEqual(func(6, undefined), 6); + assert.strictEqual(func(undefined, 4), 4); }); - QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) { + QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) { assert.expect(1); if (!isNpm) { - assert.strictEqual(_(1).subtract(2), -1); + var actual = _(1)[methodName](2); + assert.notOk(actual instanceof _); } else { skipAssert(assert); } }); - QUnit.test('should return a wrapped value when explicitly chaining', function(assert) { + QUnit.test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', function(assert) { assert.expect(1); if (!isNpm) { - assert.ok(_(1).chain().subtract(2) instanceof _); + var actual = _(1).chain()[methodName](2); + assert.ok(actual instanceof _); } else { skipAssert(assert); } }); - }()); + }); /*--------------------------------------------------------------------------*/