| 1 | import { Ordering } from "effect" |
| 2 | import { deepStrictEqual } from "node:assert" |
| 3 | import { describe, it } from "vitest" |
| 4 | |
| 5 | describe("Ordering", () => { |
| 6 | it("Reducer", () => { |
| 7 | const R = Ordering.Reducer |
| 8 | |
| 9 | deepStrictEqual(R.combine(-1, 1), -1) |
| 10 | deepStrictEqual(R.combine(1, -1), 1) |
| 11 | deepStrictEqual(R.combine(1, 1), 1) |
| 12 | deepStrictEqual(R.combine(0, 0), 0) |
| 13 | deepStrictEqual(R.combine(0, 1), 1) |
| 14 | deepStrictEqual(R.combine(1, 0), 1) |
| 15 | deepStrictEqual(R.combine(0, -1), -1) |
| 16 | deepStrictEqual(R.combine(-1, 0), -1) |
| 17 | }) |
| 18 | |
| 19 | it("reverse flips less-than and greater-than and leaves equal unchanged", () => { |
| 20 | deepStrictEqual(Ordering.reverse(-1), 1) |
| 21 | deepStrictEqual(Ordering.reverse(1), -1) |
| 22 | deepStrictEqual(Ordering.reverse(0), 0) |
| 23 | }) |
| 24 | |
| 25 | it("match selects the branch for the ordering in both data-first and data-last forms", () => { |
| 26 | const toMessage = Ordering.match({ |
| 27 | onLessThan: () => "less than", |
| 28 | onEqual: () => "equal", |
| 29 | onGreaterThan: () => "greater than" |
| 30 | }) |
| 31 | |
| 32 | deepStrictEqual(toMessage(-1), "less than") |
| 33 | deepStrictEqual(toMessage(0), "equal") |
| 34 | deepStrictEqual(toMessage(1), "greater than") |
| 35 | |
| 36 | deepStrictEqual( |
| 37 | Ordering.match(1, { onLessThan: () => "l", onEqual: () => "e", onGreaterThan: () => "g" }), |
| 38 | "g" |
| 39 | ) |
| 40 | }) |
| 41 | }) |