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);
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);
});
});
it("Comparable.compareTo", () => {
expect("a"[Comparable.compareTo]("a")).toBe(0);
expect("a"[Comparable.compareTo]("b")).toBeLessThan(0);
expect("b"[Comparable.compareTo]("a")).toBeGreaterThan(0);
});
});
it("Comparable.compareTo", () => {
expect("a"[Comparable.compareTo]("a")).toBe(0);
expect("a"[Comparable.compareTo]("b")).toBeLessThan(0);
expect("b"[Comparable.compareTo]("a")).toBeGreaterThan(0);
});
});