-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eric Vergnaud <[email protected]>
- Loading branch information
1 parent
2865844
commit 7d4ad89
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import HashSet from "../src/antlr4/misc/HashSet.js"; | ||
import HashCode from "../src/antlr4/misc/HashCode.js"; | ||
|
||
class Thing { | ||
|
||
value1 = Math.random(); | ||
value2 = Math.random(); | ||
|
||
hashCode() { | ||
return HashCode.hashStuff(this.value1); | ||
} | ||
|
||
equals(other) { | ||
return other instanceof Thing | ||
&& other.value1 === this.value1 | ||
&& other.value2 === this.value2; | ||
} | ||
} | ||
describe('test HashSet', () => { | ||
|
||
it("adds a thing", () => { | ||
const t1 = new Thing(); | ||
const t2 = new Thing(); | ||
const set = new HashSet(); | ||
set.add(t1); | ||
expect(set.has(t1)).toBeTrue(); | ||
expect(set.has(t2)).toBeFalse(); | ||
expect(set.length).toEqual(1); | ||
}) | ||
|
||
it("adds a thing once only", () => { | ||
const t1 = new Thing(); | ||
const set = new HashSet(); | ||
set.add(t1); | ||
set.add(t1); | ||
expect(set.has(t1)).toBeTrue(); | ||
expect(set.length).toEqual(1); | ||
}) | ||
|
||
it("adds 2 things with same hash code", () => { | ||
const t1 = new Thing(); | ||
const t2 = new Thing(); | ||
t2.value1 = t1.value1; | ||
const set = new HashSet(); | ||
set.add(t1); | ||
set.add(t2); | ||
expect(set.has(t1)).toBeTrue(); | ||
expect(set.has(t2)).toBeTrue(); | ||
expect(set.length).toEqual(2); | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters