2020-01-03 21:38:48 -08:00
|
|
|
import { moveOneLeft, moveOneRight, moveAllLeft, moveAllRight } from "./zindex";
|
2020-01-03 21:03:25 -08:00
|
|
|
|
2020-01-03 21:38:48 -08:00
|
|
|
function expectMove<T>(
|
|
|
|
fn: (elements: T[], indicesToMove: number[]) => void,
|
|
|
|
elems: T[],
|
|
|
|
indices: number[],
|
2020-01-24 12:04:54 +02:00
|
|
|
equal: T[],
|
2020-01-03 21:38:48 -08:00
|
|
|
) {
|
2020-01-03 21:03:25 -08:00
|
|
|
fn(elems, indices);
|
|
|
|
expect(elems).toEqual(equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
it("should moveOneLeft", () => {
|
|
|
|
expectMove(moveOneLeft, ["a", "b", "c", "d"], [1, 2], ["b", "c", "a", "d"]);
|
|
|
|
expectMove(moveOneLeft, ["a", "b", "c", "d"], [0], ["a", "b", "c", "d"]);
|
|
|
|
expectMove(
|
|
|
|
moveOneLeft,
|
|
|
|
["a", "b", "c", "d"],
|
|
|
|
[0, 1, 2, 3],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
expectMove(moveOneLeft, ["a", "b", "c", "d"], [1, 3], ["b", "a", "d", "c"]);
|
|
|
|
});
|
|
|
|
|
2020-01-03 21:38:48 -08:00
|
|
|
it("should moveOneRight", () => {
|
|
|
|
expectMove(moveOneRight, ["a", "b", "c", "d"], [1, 2], ["a", "d", "b", "c"]);
|
|
|
|
expectMove(moveOneRight, ["a", "b", "c", "d"], [3], ["a", "b", "c", "d"]);
|
|
|
|
expectMove(
|
|
|
|
moveOneRight,
|
|
|
|
["a", "b", "c", "d"],
|
|
|
|
[0, 1, 2, 3],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
expectMove(moveOneRight, ["a", "b", "c", "d"], [0, 2], ["b", "a", "d", "c"]);
|
|
|
|
});
|
|
|
|
|
2020-01-03 21:03:25 -08:00
|
|
|
it("should moveAllLeft", () => {
|
|
|
|
expectMove(
|
|
|
|
moveAllLeft,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[2, 5],
|
2020-01-24 12:04:54 +02:00
|
|
|
["c", "f", "a", "b", "d", "e", "g"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllLeft,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[5],
|
2020-01-24 12:04:54 +02:00
|
|
|
["f", "a", "b", "c", "d", "e", "g"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllLeft,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[0, 1, 2, 3, 4, 5, 6],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllLeft,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[0, 1, 2],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllLeft,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[4, 5, 6],
|
2020-01-24 12:04:54 +02:00
|
|
|
["e", "f", "g", "a", "b", "c", "d"],
|
2020-01-03 21:03:25 -08:00
|
|
|
);
|
|
|
|
});
|
2020-01-03 21:38:48 -08:00
|
|
|
|
|
|
|
it("should moveAllRight", () => {
|
|
|
|
expectMove(
|
|
|
|
moveAllRight,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[2, 5],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "d", "e", "g", "c", "f"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllRight,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[5],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d", "e", "g", "f"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllRight,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[0, 1, 2, 3, 4, 5, 6],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllRight,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[0, 1, 2],
|
2020-01-24 12:04:54 +02:00
|
|
|
["d", "e", "f", "g", "a", "b", "c"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
expectMove(
|
|
|
|
moveAllRight,
|
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
|
|
|
[4, 5, 6],
|
2020-01-24 12:04:54 +02:00
|
|
|
["a", "b", "c", "d", "e", "f", "g"],
|
2020-01-03 21:38:48 -08:00
|
|
|
);
|
|
|
|
});
|