Add more math operation method tests.

This commit is contained in:
John-David Dalton
2016-03-20 10:16:03 -07:00
parent 37454b8f42
commit ab77d9d83a

View File

@@ -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);
}
});
}());
});
/*--------------------------------------------------------------------------*/