2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-11-15 10:17:44 +00:00
|
|
|
import { ascend, descend } from "./comparators.ts";
|
2022-03-21 05:57:16 +00:00
|
|
|
|
2023-12-28 04:17:21 +00:00
|
|
|
Deno.test("ascend() works as expected", () => {
|
2022-03-21 05:57:16 +00:00
|
|
|
assertEquals(ascend(2, 2), 0);
|
|
|
|
assertEquals(ascend(2, 3), -1);
|
|
|
|
assertEquals(ascend(3, 2), 1);
|
|
|
|
assertEquals(ascend("b", "b"), 0);
|
|
|
|
assertEquals(ascend("a", "b"), -1);
|
|
|
|
assertEquals(ascend("b", "a"), 1);
|
|
|
|
assertEquals(ascend("b", "b0"), -1);
|
|
|
|
assertEquals(ascend("b0", "b"), 1);
|
|
|
|
assertEquals(ascend("2020-05-20", "2020-05-20"), 0);
|
|
|
|
assertEquals(ascend("2020-05-19", "2020-05-20"), -1);
|
|
|
|
assertEquals(ascend("2020-05-20", "2020-05-19"), 1);
|
|
|
|
assertEquals(ascend(new Date("2020-05-20"), new Date("2020-05-20")), 0);
|
|
|
|
assertEquals(ascend(new Date("2020-05-19"), new Date("2020-05-20")), -1);
|
|
|
|
assertEquals(ascend(new Date("2020-05-20"), new Date("2020-05-19")), 1);
|
|
|
|
assertEquals(ascend<string | number>(-10, "-10"), 0);
|
|
|
|
assertEquals(ascend<string | number>("-10", -10), 0);
|
|
|
|
assertEquals(ascend<string | number>(-9, "-10"), 1);
|
|
|
|
assertEquals(ascend<string | number>("-9", -10), 1);
|
|
|
|
assertEquals(ascend<string | number>(-10, "-9"), -1);
|
|
|
|
assertEquals(ascend<string | number>("-10", -9), -1);
|
|
|
|
});
|
|
|
|
|
2023-12-28 04:17:21 +00:00
|
|
|
Deno.test("descend() works as expected", () => {
|
2022-03-21 05:57:16 +00:00
|
|
|
assertEquals(descend(2, 2), 0);
|
|
|
|
assertEquals(descend(2, 3), 1);
|
|
|
|
assertEquals(descend(3, 2), -1);
|
|
|
|
assertEquals(descend("b", "b"), 0);
|
|
|
|
assertEquals(descend("a", "b"), 1);
|
|
|
|
assertEquals(descend("b", "a"), -1);
|
|
|
|
assertEquals(descend("b", "b0"), 1);
|
|
|
|
assertEquals(descend("b0", "b"), -1);
|
|
|
|
assertEquals(descend("2020-05-20", "2020-05-20"), 0);
|
|
|
|
assertEquals(descend("2020-05-19", "2020-05-20"), 1);
|
|
|
|
assertEquals(descend("2020-05-20", "2020-05-19"), -1);
|
|
|
|
assertEquals(descend(new Date("2020-05-20"), new Date("2020-05-20")), 0);
|
|
|
|
assertEquals(descend(new Date("2020-05-19"), new Date("2020-05-20")), 1);
|
|
|
|
assertEquals(descend(new Date("2020-05-20"), new Date("2020-05-19")), -1);
|
|
|
|
assertEquals(descend<string | number>(-10, "-10"), 0);
|
|
|
|
assertEquals(descend<string | number>("-10", -10), 0);
|
|
|
|
assertEquals(descend<string | number>(-9, "-10"), -1);
|
|
|
|
assertEquals(descend<string | number>("-9", -10), -1);
|
|
|
|
assertEquals(descend<string | number>(-10, "-9"), 1);
|
|
|
|
assertEquals(descend<string | number>("-10", -9), 1);
|
|
|
|
});
|