Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
72 lines (65 loc) · 2.36 KB
/
Copy pathtest.js
File metadata and controls
72 lines (65 loc) · 2.36 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import test from 'node:test'
import { deepStrictEqual } from 'node:assert'
import loadCommonElementsFinders from './loader.js'
import referenceSolution from './approaches/base.js'
const finders = await loadCommonElementsFinders()
for (const finder of finders) {
test(finder.name, async t => {
await t.test('Simple', () => {
const arr1 = [1, 2, 3]
const arr2 = [3, 4, 5]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('Empty', () => {
const arr1 = []
const arr2 = []
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('No common elements', () => {
const arr1 = [1, 2, 3]
const arr2 = [4, 5, 6]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('All common elements', () => {
const arr1 = [1, 2, 3]
const arr2 = [1, 2, 3]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('Repeated common elements', () => {
const arr1 = [1, 1, 2, 2, 3, 3]
const arr2 = [1, 2, 3]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('Repeated commons elements in both arrays', () => {
const arr1 = [1, 2, 2, 3]
const arr2 = [2, 3, 3, 4]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
await t.test('0s and 1s', () => {
const arr1 = [0, 0, 1, 1, 1, 1]
const arr2 = [0, 0, 0, 1, 1, 1]
const expected = referenceSolution(arr1, arr2)
const result = finder(arr1, arr2)
const sorted = result.toSorted((a, b) => a - b)
deepStrictEqual(sorted, expected)
})
})
}