-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathpairs.spec.js
53 lines (46 loc) · 1.6 KB
/
pairs.spec.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
53
/**************************
*
* THIS IS A TESTING FILE
*
* DO NOT MODIFY THIS FILE
*
***************************/
import pairs from "./pairs";
describe("pairs()", () => {
test("returns an empty array when passed nothing", () => {
const result = pairs();
expect(result).toEqual([]);
});
test("returns an empty array when passed an empty array", () => {
const result = pairs([]);
expect(result).toEqual([]);
});
test("returns an array with a single pair of items when passed an array with just two items", () => {
const names = ["asis", "hamsa"];
const result = pairs(names);
expect(result.length).toBe(1);
expect(result[0].length).toBe(2);
expect(result[0].includes("asis")).toBe(true);
expect(result[0].includes("hamsa")).toBe(true);
});
test("returns an array of pairs when passed multiple names", () => {
const names = ["asis", "hamsa", "fawas", "mishmish"];
const result = pairs(names);
expect(result.length).toBe(2);
expect(result.every(pair => pair.length == 2)).toBe(true);
});
test("is randomized", () => {
let names = ["asis", "hamsa", "fawas", "mishmish"];
let pairsets = [...Array(10)].map(() => pairs(names.slice(0)));
expect(
pairsets.every(
pairset => JSON.stringify(pairset) === JSON.stringify(pairsets[0])
)
).toBe(false);
});
test("can handle an odd number of names, the last array contains only one name", () => {
let names = ["asis", "hamsa", "fawas", "mishmish", "hussein"];
let result = pairs(names);
expect(result.filter(pair => pair.length === 1).length).toBe(1);
});
});