Skip to content

Commit e7a7f2d

Browse files
committed
readonlycollection tests
1 parent 9036079 commit e7a7f2d

File tree

2 files changed

+90
-16
lines changed

2 files changed

+90
-16
lines changed

test/typescript/readonlycollection.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,83 @@
11
module MxTests {
22

33

4+
function CreateCollection(): ReadOnlyCollection<number> {
5+
return new ReadOnlyCollection(new List<number>(1, 2, 3, 4, 5));
6+
}
7+
8+
9+
QUnit.module("ReadOnlyCollection");
10+
11+
12+
QUnit.test("constructor", function (assert) {
13+
assert.ok(CreateCollection().count() === 5, "initialize a ReadOnlyCollection!");
14+
15+
assert.throws(function () {
16+
new ReadOnlyCollection<number>(null);
17+
}, "throws an exception creating an ampty ReadOnlyCollection!");
18+
});
19+
20+
21+
QUnit.test("indexer", function (assert) {
22+
23+
var _col = CreateCollection();
24+
25+
assert.ok(_col[0] === 1, "indexer get!");
26+
27+
_col[0] = 0;
28+
assert.ok(_col[0] === 1, "indexer set!");
29+
30+
_col[10] = 0;
31+
assert.ok(_col[10] === undefined, "out of range indexer set!");
32+
});
33+
34+
35+
QUnit.test("get", function (assert) {
36+
37+
var _col = CreateCollection();
38+
39+
assert.ok(_col.get(1) === 2, "get item at index 1 from a collection of 5 numbers!");
40+
assert.throws(function () {
41+
_col.get(10);
42+
}, "throws error getting item at index 10 from a collection of 5 numbers!");
43+
});
44+
45+
46+
QUnit.test("contains", function (assert) {
47+
48+
var _col = CreateCollection();
49+
50+
assert.ok(_col.contains(3) === true, "collection contains!");
51+
assert.ok(_col.contains(6) === false, "collection not containing!");
52+
});
53+
54+
55+
QUnit.test("copyTo", function (assert) {
56+
57+
var _col = CreateCollection(),
58+
_arr = new Array(_col.count());
59+
60+
_col.copyTo(_arr, 0);
61+
62+
assert.deepEqual(_arr, [1, 2, 3, 4, 5], "collection copyTo an array!");
63+
assert.throws(function () {
64+
_col.copyTo([], 0);
65+
}, "throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
66+
});
67+
68+
69+
QUnit.test("indexOf", function (assert) {
70+
71+
var _col = CreateCollection();
72+
73+
assert.ok(_col.indexOf(3) === 2, "get index of 3 in a collection of first 5 numbers!");
74+
assert.ok(_col.indexOf(10) === -1, "get index of 10 in a collection of first 5 numbers!");
75+
});
76+
77+
78+
QUnit.test("collection enumerable", function (assert) {
79+
80+
var _col = CreateCollection();
81+
assert.deepEqual(_col.select(t => t * 2).where(t => t > 5).toArray(), [6, 8, 10], "select-where-toArray over a collection!");
82+
});
483
}

test/unit/readonlycollection.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ReadOnlyCollection = mx.ReadOnlyCollection;
88

99

10-
function Create() {
10+
function CreateCollection() {
1111
return new ReadOnlyCollection(new List(1, 2, 3, 4, 5));
1212
}
1313

@@ -16,7 +16,7 @@
1616

1717

1818
QUnit.test("constructor", function (assert) {
19-
assert.ok(Create().count() === 5, "initialize a ReadOnlyCollection!");
19+
assert.ok(CreateCollection().count() === 5, "initialize a ReadOnlyCollection!");
2020

2121
assert.throws(function () {
2222
new ReadOnlyCollection();
@@ -30,18 +30,21 @@
3030

3131
QUnit.test("indexer", function (assert) {
3232

33-
var _col = Create();
33+
var _col = CreateCollection();
3434

3535
assert.ok(_col[0] === 1, "indexer get!");
3636

3737
_col[0] = 0;
3838
assert.ok(_col[0] === 1, "indexer set!");
39+
40+
_col[10] = 0;
41+
assert.ok(_col[10] === undefined, "out of range indexer set!");
3942
});
4043

4144

4245
QUnit.test("get", function (assert) {
4346

44-
var _col = Create();
47+
var _col = CreateCollection();
4548

4649
assert.ok(_col.get(1) === 2, "get item at index 1 from a collection of 5 numbers!");
4750
assert.throws(function () {
@@ -52,7 +55,7 @@
5255

5356
QUnit.test("contains", function (assert) {
5457

55-
var _col = Create();
58+
var _col = CreateCollection();
5659

5760
assert.ok(_col.contains(3) === true, "collection contains!");
5861
assert.ok(_col.contains(6) === false, "collection not containing!");
@@ -61,7 +64,7 @@
6164

6265
QUnit.test("copyTo", function (assert) {
6366

64-
var _col = Create(),
67+
var _col = CreateCollection(),
6568
_arr = new Array(_col.count());
6669

6770
_col.copyTo(_arr, 0);
@@ -75,24 +78,16 @@
7578

7679
QUnit.test("indexOf", function (assert) {
7780

78-
var _col = Create();
81+
var _col = CreateCollection();
7982

8083
assert.ok(_col.indexOf(3) === 2, "get index of 3 in a collection of first 5 numbers!");
8184
assert.ok(_col.indexOf(10) === -1, "get index of 10 in a collection of first 5 numbers!");
8285
});
8386

8487

85-
QUnit.test("items", function (assert) {
86-
87-
var _col = Create();
88-
89-
assert.deepEqual(_col.items(), [1, 2, 3, 4, 5], "get collection items!");
90-
});
91-
92-
9388
QUnit.test("collection enumerable", function (assert) {
9489

95-
var _col = Create();
90+
var _col = CreateCollection();
9691
assert.deepEqual(_col.select("t => t * 2").where("t => t > 5").toArray(), [6, 8, 10], "select-where-toArray over a collection!");
9792
});
9893

0 commit comments

Comments
 (0)