Skip to content
This repository was archived by the owner on Dec 25, 2018. It is now read-only.

Commit c488863

Browse files
author
electricessence
committed
Added basic ICollection tests to Set<T>.
1 parent c5bb5ad commit c488863

File tree

6 files changed

+123
-10
lines changed

6 files changed

+123
-10
lines changed

source/System/Collections/Set.js

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/System/Collections/Set.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/System/Collections/Set.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export default class Set<T extends Primitive> implements ISet<T>, IDisposable
178178
{
179179
var type = typeof item;
180180
var t = this._registry[type];
181+
if(!t) this._registry[type] = t = {};
181182
var node:ILinkedNodeWithValue<T> = {
182183
value: item,
183184
previous: null,
@@ -192,7 +193,7 @@ export default class Set<T extends Primitive> implements ISet<T>, IDisposable
192193
clear():number
193194
{
194195
this._count = 0;
195-
wipe(this._registry,2);
196+
wipe(this._registry, 2);
196197
return this._set.clear();
197198
}
198199

@@ -229,11 +230,17 @@ export default class Set<T extends Primitive> implements ISet<T>, IDisposable
229230

230231
remove(item:T):number
231232
{
232-
var node = this._getNode(item);
233-
if(node && this._set.removeNode(node))
233+
var t = this._registry[typeof item],
234+
node = t && t[<any>item];
235+
236+
if(node)
234237
{
235-
--this._count;
236-
return 1;
238+
delete t[<any>item];
239+
if(this._set.removeNode(node))
240+
{
241+
--this._count;
242+
return 1;
243+
}
237244
}
238245
return 0;
239246
}

tests/mocha/System/Collections/Set.js

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/mocha/System/Collections/Set.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
///<reference path="../../import.d.ts"/>
2+
///<reference path="../../../../source/System/Primitive.d.ts"/>
3+
4+
import * as ICollectionTests from "./ICollection";
5+
import Set from "../../../../source/System/Collections/Set";
6+
var assert = require('../../../../node_modules/assert/assert');
7+
8+
//noinspection SpellCheckingInspection
9+
ICollectionTests.Collection('Set<' + 'string>', new Set<string>(), [
10+
"",
11+
"lorem",
12+
"ipsum",
13+
"dolem"
14+
]);
15+
16+
ICollectionTests.Collection('Set<' + 'number>', new Set<number>(), [
17+
0,
18+
1,
19+
2,
20+
3,
21+
5,
22+
7,
23+
11,
24+
13
25+
]);
26+
27+
28+
ICollectionTests.Collection('Set<' + 'Primitive>', new Set<Primitive>(), [
29+
0,
30+
1,
31+
2,
32+
3,
33+
5,
34+
7,
35+
11,
36+
13,
37+
"",
38+
"0",
39+
"1",
40+
"2",
41+
"3",
42+
"5",
43+
"7",
44+
"11",
45+
"13",
46+
true,
47+
false
48+
49+
]);

0 commit comments

Comments
 (0)