-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongest-common-prefix.js
52 lines (39 loc) · 1.36 KB
/
longest-common-prefix.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
41
42
43
44
45
46
47
48
49
50
51
52
const moduleLongestCommonPrefix = require('../js/longest-common-prefix.js');
const longestCommonPrefix = moduleLongestCommonPrefix.longestCommonPrefix;
QUnit.module('Longest Common Prefix');
QUnit.test('Matching 3 strings', assert => {
var aTestData = ["flower", "flow", "flight"];
var sExpected = "fl";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});
QUnit.test('Matching 4 strings', assert => {
var aTestData = ["flower", "flow", "flight", "fox"];
var sExpected = "f";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});
QUnit.test('Matching 5 strings', assert => {
var aTestData = ["flower", "flow", "flight", "fly", "fluent"];
var sExpected = "fl";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});
QUnit.test('Non-matching 3 strings', assert => {
var aTestData = ["dog", "racecar", "car"];
var sExpected = "";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});
QUnit.test('Single string', assert => {
var aTestData = ["dog"];
var sExpected = "dog";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});
QUnit.test('No string', assert => {
var aTestData = [];
var sExpected = "";
var sActual = longestCommonPrefix(aTestData);
assert.equal(sActual, sExpected);
});