improve naming of tests
This commit is contained in:
parent
cee294f5a7
commit
bceee7978e
1 changed files with 221 additions and 274 deletions
|
@ -39,306 +39,253 @@ const moveLexicographicallyTest = (
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("stringOrderField", () => {
|
describe("stringOrderField", () => {
|
||||||
it("stringToBase", () => {
|
describe("midPointsBetweenStrings", () => {
|
||||||
expect(Number(stringToBase(""))).toBe(0);
|
it("should work", () => {
|
||||||
expect(Number(stringToBase(" "))).toBe(1);
|
expect(averageBetweenStrings("!!", "##")).toBe('""');
|
||||||
expect(Number(stringToBase("a"))).toBe(66);
|
const midpoints = ["a", ...midPointsBetweenStrings("a", "e", 3, 1), "e"].sort();
|
||||||
expect(Number(stringToBase(" !"))).toBe(97);
|
expect(midpoints[0]).toBe("a");
|
||||||
expect(Number(stringToBase("aa"))).toBe(6336);
|
expect(midpoints[4]).toBe("e");
|
||||||
expect(Number(stringToBase("cat"))).toBe(620055);
|
expect(midPointsBetweenStrings(" ", "!'Tu:}", 1, 50)).toStrictEqual([" S:J\\~"]);
|
||||||
expect(Number(stringToBase("doggo"))).toBe(5689339845);
|
});
|
||||||
expect(Number(stringToBase("a", "abcdefghijklmnopqrstuvwxyz"))).toEqual(1);
|
|
||||||
expect(Number(stringToBase("a"))).toEqual(66);
|
it("should return empty array when the request is not possible", () => {
|
||||||
expect(Number(stringToBase("c", "abcdefghijklmnopqrstuvwxyz"))).toEqual(3);
|
expect(midPointsBetweenStrings("a", "e", 0, 1)).toStrictEqual([]);
|
||||||
expect(Number(stringToBase("ab"))).toEqual(6337);
|
expect(midPointsBetweenStrings("a", "e", 4, 1)).toStrictEqual([]);
|
||||||
expect(Number(stringToBase("cb", "abcdefghijklmnopqrstuvwxyz"))).toEqual(80);
|
});
|
||||||
expect(Number(stringToBase("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))).toEqual(4.648312045971824e+78);
|
|
||||||
expect(Number(stringToBase("~".repeat(50)))).toEqual(7.776353884348688e+98);
|
|
||||||
expect(Number(stringToBase(" "))).toEqual(7820126496);
|
|
||||||
expect(Number(stringToBase(" "))).toEqual(96);
|
|
||||||
expect(Number(stringToBase(" !"))).toEqual(97);
|
|
||||||
expect(Number(stringToBase("S:J\\~"))).toEqual(4258975590);
|
|
||||||
expect(Number(stringToBase("!'Tu:}"))).toEqual(16173443434);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("baseToString", () => {
|
describe("reorderLexicographically", () => {
|
||||||
expect(baseToString(BigInt(10))).toBe(DEFAULT_ALPHABET[9]);
|
it("should work when moving left", () => {
|
||||||
expect(baseToString(BigInt(10), "abcdefghijklmnopqrstuvwxyz")).toEqual("j");
|
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 2, 1, 1);
|
||||||
expect(baseToString(BigInt(6241))).toEqual("`a");
|
});
|
||||||
expect(baseToString(BigInt(53), "abcdefghijklmnopqrstuvwxyz")).toEqual("ba");
|
|
||||||
expect(baseToString(BigInt(1234))).toBe("+}");
|
|
||||||
expect(baseToString(BigInt(0))).toBe("");
|
|
||||||
expect(baseToString(BigInt(1))).toBe(" ");
|
|
||||||
expect(baseToString(BigInt(95))).toBe("~");
|
|
||||||
expect(baseToString(BigInt(96))).toBe(" ");
|
|
||||||
expect(baseToString(BigInt(97))).toBe(" !");
|
|
||||||
expect(baseToString(BigInt(98))).toBe(' "');
|
|
||||||
expect(baseToString(BigInt(1))).toBe(" ");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("midPointsBetweenStrings", () => {
|
it("should work when moving right", () => {
|
||||||
expect(averageBetweenStrings("!!", "##")).toBe('""');
|
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 1, 2, 1);
|
||||||
const midpoints = ["a", ...midPointsBetweenStrings("a", "e", 3, 1), "e"].sort();
|
});
|
||||||
expect(midpoints[0]).toBe("a");
|
|
||||||
expect(midpoints[4]).toBe("e");
|
|
||||||
expect(midPointsBetweenStrings("a", "e", 0, 1)).toStrictEqual([]);
|
|
||||||
expect(midPointsBetweenStrings("a", "e", 4, 1)).toStrictEqual([]);
|
|
||||||
expect(midPointsBetweenStrings(" ", "!'Tu:}", 1, 50)).toStrictEqual([" S:J\\~"]);
|
|
||||||
expect(averageBetweenStrings(" ", "!!")).toBe(" P");
|
|
||||||
expect(averageBetweenStrings("! ", "!!")).toBe("! ");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("moveLexicographically left", () => {
|
it("should work when all orders are undefined", () => {
|
||||||
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 2, 1, 1);
|
moveLexicographicallyTest(
|
||||||
});
|
[undefined, undefined, undefined, undefined, undefined, undefined],
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("moveLexicographically right", () => {
|
it("should work when moving to end and all orders are undefined", () => {
|
||||||
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 1, 2, 1);
|
moveLexicographicallyTest(
|
||||||
});
|
[undefined, undefined, undefined, undefined, undefined, undefined],
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("moveLexicographically all undefined", () => {
|
it("should work when moving left and some orders are undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined, undefined, undefined],
|
["a", "c", "e", undefined, undefined, undefined],
|
||||||
4,
|
5,
|
||||||
1,
|
2,
|
||||||
2,
|
1,
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
it("moveLexicographically all undefined to end", () => {
|
moveLexicographicallyTest(
|
||||||
moveLexicographicallyTest(
|
["a", "a", "e", undefined, undefined, undefined],
|
||||||
[undefined, undefined, undefined, undefined, undefined, undefined],
|
5,
|
||||||
1,
|
1,
|
||||||
4,
|
2,
|
||||||
5,
|
);
|
||||||
);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it("moveLexicographically some undefined move left", () => {
|
it("should work moving to the start when all is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["a", "c", "e", undefined, undefined, undefined],
|
[undefined, undefined, undefined, undefined],
|
||||||
5,
|
2,
|
||||||
2,
|
0,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("moveLexicographically some undefined move left close", () => {
|
it("should work moving to the end when all is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["a", "a", "e", undefined, undefined, undefined],
|
[undefined, undefined, undefined, undefined],
|
||||||
5,
|
1,
|
||||||
1,
|
3,
|
||||||
2,
|
4,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving to the start when all is undefined", () => {
|
it("should work moving left when all is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined],
|
[undefined, undefined, undefined, undefined, undefined, undefined],
|
||||||
2,
|
4,
|
||||||
0,
|
1,
|
||||||
1,
|
2,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving to the end when all is undefined", () => {
|
it("should work moving right when all is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined],
|
[undefined, undefined, undefined, undefined],
|
||||||
1,
|
1,
|
||||||
3,
|
2,
|
||||||
4,
|
3,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving left when all is undefined", () => {
|
it("should work moving more right when all is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined, undefined, undefined],
|
[undefined, undefined, undefined, undefined, undefined, /**/ undefined, undefined],
|
||||||
4,
|
1,
|
||||||
1,
|
4,
|
||||||
2,
|
5,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving right when all is undefined", () => {
|
it("should work moving left when right is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined],
|
["20", undefined, undefined, undefined, undefined, undefined],
|
||||||
1,
|
4,
|
||||||
2,
|
2,
|
||||||
3,
|
2,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving more right when all is undefined", () => {
|
it("should work moving right when right is undefined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[undefined, undefined, undefined, undefined, undefined, /**/ undefined, undefined],
|
["50", undefined, undefined, undefined, undefined, /**/ undefined, undefined],
|
||||||
1,
|
1,
|
||||||
4,
|
4,
|
||||||
5,
|
4,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving left when right is undefined", () => {
|
it("should work moving left when right is defined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["20", undefined, undefined, undefined, undefined, undefined],
|
["10", "20", "30", "40", undefined, undefined],
|
||||||
4,
|
3,
|
||||||
2,
|
1,
|
||||||
2,
|
1,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving right when right is undefined", () => {
|
it("should work moving right when right is defined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["50", undefined, undefined, undefined, undefined, /**/ undefined, undefined],
|
["10", "20", "30", "40", "50", undefined],
|
||||||
1,
|
1,
|
||||||
4,
|
3,
|
||||||
4,
|
1,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving left when right is defined", () => {
|
it("should work moving left when all is defined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["10", "20", "30", "40", undefined, undefined],
|
["11", "13", "15", "17", "19"],
|
||||||
3,
|
2,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving right when right is defined", () => {
|
it("should work moving right when all is defined", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["10", "20", "30", "40", "50", undefined],
|
["11", "13", "15", "17", "19"],
|
||||||
1,
|
1,
|
||||||
3,
|
2,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test moving left when all is defined", () => {
|
it("should work moving left into no left space", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["11", "13", "15", "17", "19"],
|
["11", "12", "13", "14", "19"],
|
||||||
2,
|
3,
|
||||||
1,
|
1,
|
||||||
1,
|
2,
|
||||||
);
|
2,
|
||||||
});
|
);
|
||||||
|
|
||||||
it("test moving right when all is defined", () => {
|
moveLexicographicallyTest(
|
||||||
moveLexicographicallyTest(
|
[
|
||||||
["11", "13", "15", "17", "19"],
|
DEFAULT_ALPHABET.charAt(0),
|
||||||
1,
|
// Target
|
||||||
2,
|
DEFAULT_ALPHABET.charAt(1),
|
||||||
1,
|
DEFAULT_ALPHABET.charAt(2),
|
||||||
);
|
DEFAULT_ALPHABET.charAt(3),
|
||||||
});
|
DEFAULT_ALPHABET.charAt(4),
|
||||||
|
DEFAULT_ALPHABET.charAt(5),
|
||||||
|
],
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("test moving left into no left space", () => {
|
it("should work moving right into no right space", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["11", "12", "13", "14", "19"],
|
["15", "16", "17", "18", "19"],
|
||||||
3,
|
1,
|
||||||
1,
|
3,
|
||||||
2,
|
3,
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
|
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[
|
[
|
||||||
DEFAULT_ALPHABET.charAt(0),
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 5),
|
||||||
// Target
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 4),
|
||||||
DEFAULT_ALPHABET.charAt(1),
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 3),
|
||||||
DEFAULT_ALPHABET.charAt(2),
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 2),
|
||||||
DEFAULT_ALPHABET.charAt(3),
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 1),
|
||||||
DEFAULT_ALPHABET.charAt(4),
|
],
|
||||||
DEFAULT_ALPHABET.charAt(5),
|
1,
|
||||||
],
|
3,
|
||||||
5,
|
3,
|
||||||
1,
|
1,
|
||||||
5,
|
);
|
||||||
1,
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("test moving right into no right space", () => {
|
it("should work moving right into no left space", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["15", "16", "17", "18", "19"],
|
["11", "12", "13", "14", "15", "16", undefined],
|
||||||
1,
|
1,
|
||||||
3,
|
3,
|
||||||
3,
|
3,
|
||||||
2,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
[
|
["0", "1", "2", "3", "4", "5"],
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 5),
|
1,
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 4),
|
3,
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 3),
|
3,
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 2),
|
1,
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 1),
|
);
|
||||||
],
|
});
|
||||||
1,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("test moving right into no left space", () => {
|
it("should work moving left into no right space", () => {
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["11", "12", "13", "14", "15", "16", undefined],
|
["15", "16", "17", "18", "19"],
|
||||||
1,
|
4,
|
||||||
3,
|
3,
|
||||||
3,
|
4,
|
||||||
);
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
moveLexicographicallyTest(
|
moveLexicographicallyTest(
|
||||||
["0", "1", "2", "3", "4", "5"],
|
[
|
||||||
1,
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 5),
|
||||||
3,
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 4),
|
||||||
3,
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 3),
|
||||||
1,
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 2),
|
||||||
);
|
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 1),
|
||||||
});
|
],
|
||||||
|
4,
|
||||||
it("test moving left into no right space", () => {
|
3,
|
||||||
moveLexicographicallyTest(
|
4,
|
||||||
["15", "16", "17", "18", "19"],
|
1,
|
||||||
4,
|
);
|
||||||
3,
|
});
|
||||||
4,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
|
|
||||||
moveLexicographicallyTest(
|
|
||||||
[
|
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 5),
|
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 4),
|
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 3),
|
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 2),
|
|
||||||
DEFAULT_ALPHABET.charAt(DEFAULT_ALPHABET.length - 1),
|
|
||||||
],
|
|
||||||
4,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const prev = (str: string) => baseToString(stringToBase(str) - BigInt(1));
|
|
||||||
const next = (str: string) => baseToString(stringToBase(str) + BigInt(1));
|
|
||||||
|
|
||||||
it("baseN calculation is correctly consecutive", () => {
|
|
||||||
const str = "this-is-a-test";
|
|
||||||
expect(next(prev(str))).toBe(str);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rolls over sanely", () => {
|
|
||||||
const maxSpaceValue = "~".repeat(50);
|
|
||||||
const fiftyFirstChar = " ".repeat(51);
|
|
||||||
expect(next(maxSpaceValue)).toBe(fiftyFirstChar);
|
|
||||||
expect(prev(fiftyFirstChar)).toBe(maxSpaceValue);
|
|
||||||
expect(Number(stringToBase(DEFAULT_ALPHABET[0]))).toEqual(1);
|
|
||||||
expect(Number(stringToBase(DEFAULT_ALPHABET[1]))).toEqual(2);
|
|
||||||
expect(DEFAULT_ALPHABET[DEFAULT_ALPHABET.length - 1]).toBe("~");
|
|
||||||
expect(DEFAULT_ALPHABET[0]).toBe(" ");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue