Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
it("Equatable.hash", () => {
const a = Symbol("a");
expect(a[Equatable.hash]()).toBe(767180218);
});
});
it("Equatable.hash", () => {
const a = {};
expect(a[Equatable.hash]()).toBe(-467054833);
});
});