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();it("Equatable.equals", () => {
expect(1[Equatable.equals](1)).toBe(true);
expect(1[Equatable.equals](0)).toBe(false);
});
it("Equatable.hash", () => {it("Equatable.equals", () => {
const a = {};
const b = {};
expect(a[Equatable.equals](a)).toBe(true);
expect(a[Equatable.equals](b)).toBe(false);
});
it("Equatable.hash", () => {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);