ISSUE-054 - Initial work of building the Timing Board. Working so far only have work for the Timing Tower.

Timing Board is the combination of all elements on the left side of the screen, including the Status Indicator component (not written yet) that is visible whenever there are cars on track.
This commit is contained in:
Kyle Geib committed 2022-02-16 14:36:27 -05:00
1 parent 8bf413ba31
commit 22ebab1101
19 files changed
+521 -41

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import { andMatch, andWith, orMatch, orWith } from "./common";
describe("common", () => {
describe("andMatch", () => {
describe("detects correct matches", () => {
it("works with number", () => {
expect(andMatch(5, 2 + 3, 5 + 0, 6 - 1)).toBe(true);
});
it("works with boolean", () => {
expect(andMatch(true, 1 == 1, !false, !!1)).toBe(true);
});
});
describe("detects incorrect matches", () => {
it("works with number", () => {
expect(andMatch(5, 4 + 1, 3 + 0)).toBe(false);
});
it("works with boolean", () => {
expect(andMatch(true, !true, !!0)).toBe(false);
});
});
describe("sensibly handles odd situations", () => {
it("returns truthiness of self when no rights given", () => {
expect(andMatch(5)).toBe(true);
expect(andMatch(0)).toBe(false);
});
});
});
describe("orMatch", () => {
describe("detects correct matches", () => {
it("works with number", () => {
expect(orMatch(5, 0, 0, 6 - 1)).toBe(true);
});
it("works with boolean", () => {
expect(orMatch(true, false, !false)).toBe(true);
});
});
describe("detects incorrect matches", () => {
it("works with number", () => {
expect(orMatch(5, 2, 3)).toBe(false);
});
it("works with boolean", () => {
expect(orMatch(false, true, !!1)).toBe(false);
});
});
describe("sensibly handles odd situations", () => {
it("returns truthiness of self when no rights given", () => {
expect(orMatch(5)).toBe(true);
expect(orMatch(0)).toBe(false);
});
});
});
const greaterCompare = (l: number, r: number) => l > r;
describe("andWith", () => {
describe("detects correct matches", () => {
it("works with number", () => {
expect(andWith(10, greaterCompare, 5, 3, 9)).toBe(true);
});
});
describe("detects incorrect matches", () => {
it("works with number", () => {
expect(andWith(5, greaterCompare, 4, 10)).toBe(false);
});
});
describe("sensibly handles odd situations", () => {
it("returns truthiness of self when no rights given", () => {
expect(andWith(5, greaterCompare)).toBe(true);
});
});
});
describe("orWith", () => {
describe("detects correct matches", () => {
it("works with number", () => {
expect(orWith(5, greaterCompare, 10, 15, 3)).toBe(true);
});
});
describe("detects incorrect matches", () => {
it("works with number", () => {
expect(orWith(5, greaterCompare, 10, 20)).toBe(false);
});
});
describe("sensibly handles odd situations", () => {
it("returns truthiness of self when no rights given", () => {
expect(orWith(5, greaterCompare)).toBe(true);
});
});
});
});
+91
View File
@@ -0,0 +1,91 @@
/**
* Helpful utility function to save on ugly looking chains of && checks.
* Before: (myObj.modeA === MyModes.On && myObj.modeB === MyModes.On)
* After: andMatch(MyModes.On, myObj.modeA, myObj.modeB)
* Uses strict equals.
* @param left The argument you're checking.
* @param rights n arguments you're checking against.
* @returns True if all match. If no rights given returns truthiness of left.
*/
export function andMatch<T>(left: T, ...rights: T[]): boolean {
if (rights.length === 0) {
return !!left;
}
for (const right of rights) {
if (left !== right) {
return false;
}
}
return true;
}
/**
* Helpful utility function to save on ugly looking chains of || checks.
* @param left The argument you're checking.
* @param rights n arguments you're checking against.
* @returns True if any match. If no rights given returns truthiness of left.
*/
export function orMatch<T>(left: T, ...rights: T[]): boolean {
if (rights.length === 0) {
return !!left;
}
for (const right of rights) {
if (left === right) {
return true;
}
}
return false;
}
/**
* Helpful function that essentially repackages the functionality of Array.every()
* into a slightly more sensible form.
* @param left The argument you're checking.
* @param func Predicate that returns a boolean.
* @param rights n arguments you're checking against.
* @returns True if all match. If no rights given returns truthiness of left.
*/
export function andWith<T>(
left: T,
func: (l: T, r: T) => boolean,
...rights: T[]
): boolean {
if (rights.length === 0) {
return !!left;
}
for (const right of rights) {
if (!func(left, right)) {
return false;
}
}
return true;
}
/**
* Helpful function that essentially repackages the functionality of Array.some()
* into a slightly more sensible form.
* @param left The argument you're checking.
* @param func Predicate that returns a boolean.
* @param rights n arguments you're checking against.
* @returns True if any match. If no rights given returns truthiness of left.
*/
export function orWith<T>(
left: T,
func: (l: T, r: T) => boolean,
...rights: T[]
): boolean {
if (rights.length === 0) {
return !!left;
}
for (const right of rights) {
if (func(left, right)) {
return true;
}
}
return false;
}