-
Notifications
You must be signed in to change notification settings - Fork 0
/
minSwaps.test.js
31 lines (27 loc) · 983 Bytes
/
minSwaps.test.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
const minSwaps = require("./minSwaps");
describe("Amazon Swap", () => {
it("already sorted", () => {
expect(minSwaps([1, 1, 1, 0, 0, 0])).toEqual(0);
expect(minSwaps([1, 0, 0, 0])).toEqual(0);
expect(minSwaps([0, 0, 0, 1, 1])).toEqual(0);
expect(minSwaps([1, 0])).toEqual(0);
expect(minSwaps([0])).toEqual(0);
expect(minSwaps([1])).toEqual(0);
});
it("swap once", () => {
expect(minSwaps([1, 0, 1])).toEqual(1);
expect(minSwaps([0, 0, 1, 0])).toEqual(1);
expect(minSwaps([0, 1, 0, 0, 0, 0, 0])).toEqual(1);
expect(minSwaps([0, 1, 0])).toEqual(1);
expect(minSwaps([1, 1, 1, 0, 1, 0, 0])).toEqual(1);
});
it("swap twice", () => {
expect(minSwaps([0, 1, 1, 0, 0])).toEqual(2);
expect(minSwaps([1, 0, 0, 1, 0])).toEqual(2);
expect(minSwaps([1, 0, 1, 1, 0])).toEqual(2);
});
it("swap thrice", () => {
expect(minSwaps([0, 1, 1, 1, 0])).toEqual(3);
expect(minSwaps([1, 0, 1, 0, 1, 0])).toEqual(3);
});
});