improve naming of tests

This commit is contained in:
Michael Telatynski 2021-06-16 09:30:47 +01:00
parent cee294f5a7
commit bceee7978e

View File

@ -39,64 +39,31 @@ const moveLexicographicallyTest = (
};
describe("stringOrderField", () => {
it("stringToBase", () => {
expect(Number(stringToBase(""))).toBe(0);
expect(Number(stringToBase(" "))).toBe(1);
expect(Number(stringToBase("a"))).toBe(66);
expect(Number(stringToBase(" !"))).toBe(97);
expect(Number(stringToBase("aa"))).toBe(6336);
expect(Number(stringToBase("cat"))).toBe(620055);
expect(Number(stringToBase("doggo"))).toBe(5689339845);
expect(Number(stringToBase("a", "abcdefghijklmnopqrstuvwxyz"))).toEqual(1);
expect(Number(stringToBase("a"))).toEqual(66);
expect(Number(stringToBase("c", "abcdefghijklmnopqrstuvwxyz"))).toEqual(3);
expect(Number(stringToBase("ab"))).toEqual(6337);
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", () => {
expect(baseToString(BigInt(10))).toBe(DEFAULT_ALPHABET[9]);
expect(baseToString(BigInt(10), "abcdefghijklmnopqrstuvwxyz")).toEqual("j");
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", () => {
describe("midPointsBetweenStrings", () => {
it("should work", () => {
expect(averageBetweenStrings("!!", "##")).toBe('""');
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 return empty array when the request is not possible", () => {
expect(midPointsBetweenStrings("a", "e", 0, 1)).toStrictEqual([]);
expect(midPointsBetweenStrings("a", "e", 4, 1)).toStrictEqual([]);
});
});
describe("reorderLexicographically", () => {
it("should work when moving left", () => {
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 2, 1, 1);
});
it("moveLexicographically right", () => {
it("should work when moving right", () => {
moveLexicographicallyTest(["a", "c", "e", "g", "i"], 1, 2, 1);
});
it("moveLexicographically all undefined", () => {
it("should work when all orders are undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined, undefined, undefined],
4,
@ -105,7 +72,7 @@ describe("stringOrderField", () => {
);
});
it("moveLexicographically all undefined to end", () => {
it("should work when moving to end and all orders are undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined, undefined, undefined],
1,
@ -114,16 +81,14 @@ describe("stringOrderField", () => {
);
});
it("moveLexicographically some undefined move left", () => {
it("should work when moving left and some orders are undefined", () => {
moveLexicographicallyTest(
["a", "c", "e", undefined, undefined, undefined],
5,
2,
1,
);
});
it("moveLexicographically some undefined move left close", () => {
moveLexicographicallyTest(
["a", "a", "e", undefined, undefined, undefined],
5,
@ -132,7 +97,7 @@ describe("stringOrderField", () => {
);
});
it("test moving to the start when all is undefined", () => {
it("should work moving to the start when all is undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined],
2,
@ -141,7 +106,7 @@ describe("stringOrderField", () => {
);
});
it("test moving to the end when all is undefined", () => {
it("should work moving to the end when all is undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined],
1,
@ -150,7 +115,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left when all is undefined", () => {
it("should work moving left when all is undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined, undefined, undefined],
4,
@ -159,7 +124,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right when all is undefined", () => {
it("should work moving right when all is undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined],
1,
@ -168,7 +133,7 @@ describe("stringOrderField", () => {
);
});
it("test moving more right when all is undefined", () => {
it("should work moving more right when all is undefined", () => {
moveLexicographicallyTest(
[undefined, undefined, undefined, undefined, undefined, /**/ undefined, undefined],
1,
@ -177,7 +142,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left when right is undefined", () => {
it("should work moving left when right is undefined", () => {
moveLexicographicallyTest(
["20", undefined, undefined, undefined, undefined, undefined],
4,
@ -186,7 +151,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right when right is undefined", () => {
it("should work moving right when right is undefined", () => {
moveLexicographicallyTest(
["50", undefined, undefined, undefined, undefined, /**/ undefined, undefined],
1,
@ -195,7 +160,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left when right is defined", () => {
it("should work moving left when right is defined", () => {
moveLexicographicallyTest(
["10", "20", "30", "40", undefined, undefined],
3,
@ -204,7 +169,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right when right is defined", () => {
it("should work moving right when right is defined", () => {
moveLexicographicallyTest(
["10", "20", "30", "40", "50", undefined],
1,
@ -213,7 +178,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left when all is defined", () => {
it("should work moving left when all is defined", () => {
moveLexicographicallyTest(
["11", "13", "15", "17", "19"],
2,
@ -222,7 +187,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right when all is defined", () => {
it("should work moving right when all is defined", () => {
moveLexicographicallyTest(
["11", "13", "15", "17", "19"],
1,
@ -231,7 +196,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left into no left space", () => {
it("should work moving left into no left space", () => {
moveLexicographicallyTest(
["11", "12", "13", "14", "19"],
3,
@ -257,7 +222,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right into no right space", () => {
it("should work moving right into no right space", () => {
moveLexicographicallyTest(
["15", "16", "17", "18", "19"],
1,
@ -281,7 +246,7 @@ describe("stringOrderField", () => {
);
});
it("test moving right into no left space", () => {
it("should work moving right into no left space", () => {
moveLexicographicallyTest(
["11", "12", "13", "14", "15", "16", undefined],
1,
@ -298,7 +263,7 @@ describe("stringOrderField", () => {
);
});
it("test moving left into no right space", () => {
it("should work moving left into no right space", () => {
moveLexicographicallyTest(
["15", "16", "17", "18", "19"],
4,
@ -321,24 +286,6 @@ describe("stringOrderField", () => {
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(" ");
});
});