11module 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}
0 commit comments