-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ecs): update VersionedIDGen, add tests
- Loading branch information
1 parent
9a01b4e
commit 118405d
Showing
2 changed files
with
59 additions
and
18 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
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,26 @@ | ||
import * as assert from "assert"; | ||
import { VersionedIDGen } from "../src"; | ||
|
||
describe("VersionedIDGen", () => { | ||
it("reuse", () => { | ||
const g = new VersionedIDGen(8); | ||
assert.equal(g.next(), 0); | ||
assert.equal(g.next(), 1); | ||
assert.equal(g.next(), 2); | ||
assert(g.free(1)); | ||
assert(g.free(2)); | ||
assert.equal(g.next(), 0x102); | ||
assert.equal(g.next(), 0x101); | ||
assert.equal(g.next(), 3); | ||
assert(g.free(0)); | ||
assert(!g.free(0)); | ||
assert.equal(g.next(), 0x100); | ||
assert(g.free(0x100)); | ||
assert(g.free(3)); | ||
assert.equal((<any>g).freeID, 0x103); | ||
assert(g.free(0x101)); | ||
assert(g.free(0x102)); | ||
assert.equal((<any>g).freeID, 0x202); | ||
assert.deepEqual((<any>g).ids, [-1, 0x103, 0x201, 0x200]); | ||
}); | ||
}); |