Spaces:
Configuration error
Configuration error
File size: 1,623 Bytes
9f21d0a | 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 32 33 34 35 36 37 38 39 40 | import { describe, expect, test } from "vitest";
import { sameValue } from "./equality";
describe("sameValue", () => {
test("primitives", () => {
expect(sameValue("a", "a")).toBe(true);
expect(sameValue("a", "b")).toBe(false);
expect(sameValue(false, false)).toBe(true);
expect(sameValue(null, null)).toBe(true);
expect(sameValue(null, "")).toBe(false);
});
// The case every caller actually has: a freshly decoded array that happens to
// hold the same names as the one already in the store.
test("equal lists that are not the same array", () => {
expect(sameValue(["Weather", "GNSS"], ["Weather", "GNSS"])).toBe(true);
expect(sameValue(["Weather", "GNSS"], ["GNSS", "Weather"])).toBe(false);
expect(sameValue(["Weather"], ["Weather", "GNSS"])).toBe(false);
expect(sameValue([], [])).toBe(true);
});
test("ground stations compare field by field", () => {
expect(sameValue([{ lat: 48.1, lon: 11.5, name: "Munich" }], [{ lat: 48.1, lon: 11.5, name: "Munich" }])).toBe(true);
expect(sameValue([{ lat: 48.1, lon: 11.5 }], [{ lat: 48.1, lon: 11.6 }])).toBe(false);
});
// A named and an unnamed station are different stations, and JSON key order
// is not what decides it.
test("a missing key is not the same as an extra one", () => {
expect(sameValue([{ lat: 1, lon: 2 }], [{ lat: 1, lon: 2, name: "x" }])).toBe(false);
expect(sameValue({ lat: 1, lon: 2 }, { lon: 2, lat: 1 })).toBe(true);
});
test("mixed types never compare equal", () => {
expect(sameValue(["a"], "a")).toBe(false);
expect(sameValue({}, [])).toBe(false);
});
});
|