Skip to content

Commit 326b18f

Browse files
committed
typescript tests
1 parent cd5dbd7 commit 326b18f

File tree

11 files changed

+569
-99
lines changed

11 files changed

+569
-99
lines changed

test/typescript/dictionary.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
QUnit.test("constructor", function (assert) {
2020

21-
var _comparer = EqualityComparer.create(
22-
function (o) { return mx.hash(o); },
23-
function (a, b) { return a === b; }
24-
),
21+
var _comparer = EqualityComparer.create(o => mx.hash(o), (a, b) => a === b),
2522
_d1 = new Dictionary<number, string>(),
2623
_d2 = new Dictionary<number, string>(CreateDictionary()),
2724
_d3 = new Dictionary<number, string>(_comparer),
@@ -44,9 +41,7 @@
4441
_dic.add(1, "A");
4542

4643
assert.ok(_dic.count() === 1, "ditionary add");
47-
assert.throws(function () {
48-
_dic.add(1, "B");
49-
}, "throws an error adding duplicate key");
44+
assert.throws(() => _dic.add(1, "B"), "throws an error adding duplicate key");
5045
});
5146

5247

@@ -82,11 +77,8 @@
8277
_arr = new Array(_dic.count());
8378

8479
_dic.copyTo(_arr, 0);
85-
8680
assert.deepEqual(_arr, [1, 2, 3, 4, 5], "dictionary copy to an array!");
87-
assert.throws(function () {
88-
_dic.copyTo([], 0);
89-
}, "throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
81+
assert.throws(() => _dic.copyTo([], 0), "throws an error when the number of elements is greater than the number of elements that the destination array can contain!");
9082
});
9183

9284

@@ -113,17 +105,15 @@
113105
var _dic = CreateDictionary();
114106

115107
assert.ok(_dic.get(1) === "A", "dictionary get value!");
116-
assert.throws(function () {
117-
_dic.get(10);
118-
}, "throws an error getting non existing key!");
108+
assert.throws(() => _dic.get(10), "throws an error getting non existing key!");
119109
});
120110

121111

122112
QUnit.test("set", function (assert) {
123113

124114
var _dic = CreateDictionary();
115+
125116
_dic.set(1, "AA");
126-
127117
assert.ok(_dic.get(1) === "AA", "dictionary set value!");
128118

129119
_dic.set(6, "F");
@@ -137,10 +127,7 @@
137127

138128
assert.ok(function () {
139129
var value: string;
140-
141-
var res = _dic.tryGetValue(1, function (val) {
142-
value = val;
143-
});
130+
var res = _dic.tryGetValue(1, val => value = val);
144131

145132
return res && value === "A";
146133

@@ -149,10 +136,7 @@
149136

150137
assert.ok(function () {
151138
var value: string;
152-
153-
var res = _dic.tryGetValue(10, function (val) {
154-
value = val;
155-
});
139+
var res = _dic.tryGetValue(10, val => value = val);
156140

157141
return res === false;
158142

0 commit comments

Comments
 (0)