-
Notifications
You must be signed in to change notification settings - Fork 0
/
two-sum.js
40 lines (31 loc) · 1.05 KB
/
two-sum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const moduleTwoSum = require('../js/two-sum.js');
const twoSum = moduleTwoSum.twoSum;
QUnit.module('Two Sum');
QUnit.test('2 elements', assert => {
var aTestNums = [3, 3];
var nTestTarget = 6;
var aExpectedIndices = [0, 1];
var nActualIndices = twoSum(aTestNums, nTestTarget);
assert.deepEqual(nActualIndices, aExpectedIndices);
});
QUnit.test('3 elements', assert => {
var aTestNums = [3, 2, 4];
var nTestTarget = 6;
var aExpectedIndices = [1, 2];
var nActualIndices = twoSum(aTestNums, nTestTarget);
assert.deepEqual(nActualIndices, aExpectedIndices);
});
QUnit.test('4 elements', assert => {
var aTestNums = [2, 7, 11, 15];
var nTestTarget = 9;
var aExpectedIndices = [0, 1];
var nActualIndices = twoSum(aTestNums, nTestTarget);
assert.deepEqual(nActualIndices, aExpectedIndices);
});
QUnit.test('Non matching elements', assert => {
var aTestNums = [1, 2, 3, 4, 5];
var nTestTarget = 17;
var aExpectedIndices = [];
var nActualIndices = twoSum(aTestNums, nTestTarget);
assert.deepEqual(nActualIndices, aExpectedIndices);
});