Skip to content

Commit b2a4244

Browse files
committed
add tests for sortableset
1 parent 5f16dd8 commit b2a4244

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎test/SortableSet.test.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* globals describe, it */
2+
"use strict";
3+
4+
const SortableSet = require("../lib/util/SortableSet");
5+
6+
describe("util/SortableSet", () => {
7+
it("Can be constructed like a normal Set", () => {
8+
const sortableSet = new SortableSet([1,1,1,1,1,4,5,2], () =>{});
9+
Array.from(sortableSet).should.eql([1,4,5,2]);
10+
});
11+
12+
it("Can sort its content", () => {
13+
const sortableSet = new SortableSet([1,1,1,6,6,1,1,4,5,2,3,8,5,7,9,0,3,1], (a,b) => a - b);
14+
sortableSet.sort();
15+
Array.from(sortableSet).should.eql([0,1,2,3,4,5,6,7,8,9]);
16+
});
17+
18+
it("Can sort by a specified function", () => {
19+
const sortableSet = new SortableSet([1,1,1,6,6,1,1,4,5,2,3,8,5,7,9,0,3,1], (a,b) => a - b);
20+
sortableSet.sortWith((a,b)=> b - a);
21+
Array.from(sortableSet).should.eql([9,8,7,6,5,4,3,2,1,0]);
22+
});
23+
});

0 commit comments

Comments
 (0)