How to use @esfx/equatable - 10 common examples

To help you get started, we’ve selected a few @esfx/equatable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esfx / esfx / packages / collections-hashset / src / __tests__ / hashSet.ts View on Github external
import { Equatable, Equaler } from "@esfx/equatable";
import { HashSet } from '../';

class Point {
    constructor(readonly x: number, readonly y: number) {
    }

    [Equatable.equals](other: unknown) {
        return other instanceof Point
            && this.x === other.x
            && this.y === other.y;
    }

    [Equatable.hash]() {
        return Equaler.defaultEqualer.hash(this.x)
             ^ Equaler.defaultEqualer.hash(this.y);
    }
}

it("add", () => {
    const p0 = new Point(10, 20);
    const p1 = new Point(10, 20);
    const p2 = new Point(30, 40);
    const set = new HashSet();
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Equatable.equals", () => {
            expect(1[Equatable.equals](1)).toBe(true);
            expect(1[Equatable.equals](0)).toBe(false);
        });
        it("Equatable.hash", () => {
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Equatable.equals", () => {
            const a = {};
            const b = {};
            expect(a[Equatable.equals](a)).toBe(true);
            expect(a[Equatable.equals](b)).toBe(false);
        });
        it("Equatable.hash", () => {
github esfx / esfx / packages / collections-multimap / src / __tests__ / multiMap.ts View on Github external
import { Equatable, Equaler } from "@esfx/equatable";
import { MultiMap } from '..';

class Point {
    constructor(readonly x: number, readonly y: number) {
    }

    [Equatable.equals](other: unknown) {
        return other instanceof Point
            && this.x === other.x
            && this.y === other.y;
    }

    [Equatable.hash]() {
        return Equaler.defaultEqualer.hash(this.x)
             ^ Equaler.defaultEqualer.hash(this.y);
    }
}

it("add", () => {
    const p0 = new Point(10, 20);
    const p1 = new Point(10, 20);
    const p2 = new Point(30, 40);
    const p3 = new Point(30, 40);
github esfx / esfx / packages / collections-hashset / src / __tests__ / hashSet.ts View on Github external
import { Equatable, Equaler } from "@esfx/equatable";
import { HashSet } from '../';

class Point {
    constructor(readonly x: number, readonly y: number) {
    }

    [Equatable.equals](other: unknown) {
        return other instanceof Point
            && this.x === other.x
            && this.y === other.y;
    }

    [Equatable.hash]() {
        return Equaler.defaultEqualer.hash(this.x)
             ^ Equaler.defaultEqualer.hash(this.y);
    }
}

it("add", () => {
    const p0 = new Point(10, 20);
    const p1 = new Point(10, 20);
    const p2 = new Point(30, 40);
    const set = new HashSet();
    set.add(p0);
    set.add(p1);
    set.add(p2);
    expect(set.size).toBe(2);
    expect(set.has(p0)).toBe(true);
    expect(set.has(p1)).toBe(true);
github esfx / esfx / packages / collections-multimap / src / __tests__ / multiMap.ts View on Github external
import { Equatable, Equaler } from "@esfx/equatable";
import { MultiMap } from '..';

class Point {
    constructor(readonly x: number, readonly y: number) {
    }

    [Equatable.equals](other: unknown) {
        return other instanceof Point
            && this.x === other.x
            && this.y === other.y;
    }

    [Equatable.hash]() {
        return Equaler.defaultEqualer.hash(this.x)
             ^ Equaler.defaultEqualer.hash(this.y);
    }
}

it("add", () => {
    const p0 = new Point(10, 20);
    const p1 = new Point(10, 20);
    const p2 = new Point(30, 40);
    const p3 = new Point(30, 40);
    const set = new MultiMap();
    set.add("a", p0);
    set.add("a", p1);
    set.add("a", p2);
    set.add("b", p3);
    expect(set.size).toBe(3);
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Equatable.hash", () => {
            const a = Symbol("a");
            expect(a[Equatable.hash]()).toBe(767180218);
        });
    });
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Equatable.hash", () => {
            const a = {};
            expect(a[Equatable.hash]()).toBe(-467054833);
        });
    });
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Comparable.compareTo", () => {
            expect("a"[Comparable.compareTo]("a")).toBe(0);
            expect("a"[Comparable.compareTo]("b")).toBeLessThan(0);
            expect("b"[Comparable.compareTo]("a")).toBeGreaterThan(0);
        });
    });
github esfx / esfx / packages / equatable-shim / src / __tests__ / global.ts View on Github external
it("Comparable.compareTo", () => {
            expect("a"[Comparable.compareTo]("a")).toBe(0);
            expect("a"[Comparable.compareTo]("b")).toBeLessThan(0);
            expect("b"[Comparable.compareTo]("a")).toBeGreaterThan(0);
        });
    });

@esfx/equatable

A low-level API for defining equality.

Apache-2.0
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages