Skip to content

Commit 3ff1ea8

Browse files
committed
collection tests
1 parent 2cf669b commit 3ff1ea8

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

Multiplex.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Content Include="test\unit\linkedlist.js" />
6969
<Content Include="test\unit\lookup.js" />
7070
<Content Include="test\unit\runtime.js" />
71+
<Content Include="test\unit\collection.js" />
7172
<Content Include="test\unit\stack.js" />
7273
<Content Include="test\unit\queue.js" />
7374
<Content Include="test\unit\sortedlist.js" />
@@ -98,6 +99,7 @@
9899
<TypeScriptCompile Include="test\typescript\readonlycollection.ts" />
99100
<TypeScriptCompile Include="test\typescript\runtime.ts" />
100101
<TypeScriptCompile Include="test\typescript\sortedlist.ts" />
102+
<TypeScriptCompile Include="test\typescript\collection.ts" />
101103
<TypeScriptCompile Include="test\typescript\stack.ts" />
102104
</ItemGroup>
103105
<ItemGroup>

test/mx.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<script src="unit/mx.js"></script>
1111
<script src="unit/runtime.js"></script>
1212
<script src="unit/linq.js"></script>
13+
<script src="unit/collection.js"></script>
1314
<script src="unit/list.js"></script>
1415
<script src="unit/readonlycollection.js"></script>
1516
<script src="unit/sortedlist.js"></script>

test/typescript/collection.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module MxTests {
2+
3+
import Collection = mx.Collection;
4+
5+
6+
7+
/* Factory methods
8+
---------------------------------------------------------------------- */
9+
10+
function CreateCollection(): Collection<number> {
11+
return new Collection(mx.range(1, 5));
12+
}
13+
14+
15+
16+
/* Tests
17+
---------------------------------------------------------------------- */
18+
19+
QUnit.module("Collection");
20+
21+
22+
QUnit.test("constructor", function (assert) {
23+
24+
assert.ok(CreateCollection().count() === 5, "initialize a Collection using specified collection!");
25+
});
26+
27+
28+
QUnit.test("count", function (assert) {
29+
30+
var _col = CreateCollection();
31+
assert.ok(_col.count() === 5, "collection containing count!");
32+
assert.throws(() => new Collection().count(), "throws an error getting count of an empty collection.");
33+
});
34+
35+
36+
QUnit.test("copyTo", function (assert) {
37+
38+
var _col = CreateCollection(),
39+
_arr = new Array(_col.count());
40+
41+
_col.copyTo(_arr, 0);
42+
43+
assert.deepEqual(_arr, [1, 2, 3, 4, 5], "Collection copy to an array!");
44+
assert.throws(() => _col.copyTo([], 0), "throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
45+
});
46+
47+
48+
QUnit.test("collection enumerable", function (assert) {
49+
50+
var _col = CreateCollection();
51+
assert.deepEqual(_col.select(t => t * 2).where(t => t > 5).toArray(), [6, 8, 10], "select-where-toArray over a collection!");
52+
});
53+
}

test/unit/collection.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/// <reference path="../data/_references.js" />
2+
3+
4+
(function () {
5+
6+
var Collection = mx.Collection;
7+
8+
9+
10+
/* Factory methods
11+
---------------------------------------------------------------------- */
12+
13+
function CreateCollection() {
14+
return new Collection(mx.range(1, 5));
15+
}
16+
17+
18+
19+
/* Tests
20+
---------------------------------------------------------------------- */
21+
22+
QUnit.module("Collection");
23+
24+
25+
QUnit.test("constructor", function (assert) {
26+
27+
assert.ok(CreateCollection().count() === 5, "initialize a Collection using specified collection!");
28+
});
29+
30+
31+
QUnit.test("count", function (assert) {
32+
33+
var _col = CreateCollection();
34+
assert.ok(_col.count() === 5, "collection containing count!");
35+
assert.throws(function () {
36+
new Collection().count();
37+
}, "throws an error getting count of an empty collection.");
38+
});
39+
40+
41+
QUnit.test("copyTo", function (assert) {
42+
43+
var _col = CreateCollection(),
44+
_arr = new Array(_col.count());
45+
46+
_col.copyTo(_arr, 0);
47+
48+
assert.deepEqual(_arr, [1, 2, 3, 4, 5], "Collection copy to an array!");
49+
assert.throws(function () {
50+
_col.copyTo([], 0);
51+
}, "throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
52+
});
53+
54+
55+
QUnit.test("collection enumerable", function (assert) {
56+
57+
var _col = CreateCollection();
58+
assert.deepEqual(_col.select("t => t * 2").where("t => t > 5").toArray(), [6, 8, 10], "select-where-toArray over a collection!");
59+
});
60+
61+
})(window);

0 commit comments

Comments
 (0)