|
1 | 1 | $(document).ready(function() { |
2 | 2 |
|
3 | | - module("underscore.array.selectors"); |
| 3 | + QUnit.module("underscore.array.selectors"); |
4 | 4 |
|
5 | | - test("second", function() { |
| 5 | + QUnit.test("second", function(assert) { |
6 | 6 | var a = [1,2,3,4,5]; |
7 | 7 |
|
8 | | - equal(_.second(a), 2, 'should retrieve the 2nd element in an array'); |
9 | | - deepEqual(_.second(a, 5), [2,3,4,5], 'should retrieve all but the first element in an array'); |
10 | | - deepEqual(_.map([a,_.rest(a)], _.second), [2,3], 'should be usable in _.map'); |
| 8 | + assert.equal(_.second(a), 2, 'should retrieve the 2nd element in an array'); |
| 9 | + assert.deepEqual(_.second(a, 5), [2,3,4,5], 'should retrieve all but the first element in an array'); |
| 10 | + assert.deepEqual(_.map([a,_.rest(a)], _.second), [2,3], 'should be usable in _.map'); |
11 | 11 | }); |
12 | 12 |
|
13 | | - test("third", function() { |
| 13 | + QUnit.test("third", function(assert) { |
14 | 14 | var a = [1,2,3,4,5]; |
15 | 15 |
|
16 | | - equal(_.third(a), 3, 'should retrieve the 3rd element in an array'); |
17 | | - deepEqual(_.third(a, 5), [3,4,5], 'should retrieve all but the first and second element in an array'); |
18 | | - deepEqual(_.map([a,_.rest(a)], _.third), [3,4], 'should be usable in _.map'); |
| 16 | + assert.equal(_.third(a), 3, 'should retrieve the 3rd element in an array'); |
| 17 | + assert.deepEqual(_.third(a, 5), [3,4,5], 'should retrieve all but the first and second element in an array'); |
| 18 | + assert.deepEqual(_.map([a,_.rest(a)], _.third), [3,4], 'should be usable in _.map'); |
19 | 19 | }); |
20 | 20 |
|
21 | | - test("takeWhile", function() { |
| 21 | + QUnit.test("takeWhile", function(assert) { |
22 | 22 | var isNeg = function(n) { return n < 0; }; |
23 | 23 |
|
24 | | - deepEqual(_.takeWhile([-2,-1,0,1,2], isNeg), [-2,-1], 'should take elements until a function goes truthy'); |
25 | | - deepEqual(_.takeWhile([1,-2,-1,0,1,2], isNeg), [], 'should take elements until a function goes truthy'); |
| 24 | + assert.deepEqual(_.takeWhile([-2,-1,0,1,2], isNeg), [-2,-1], 'should take elements until a function goes truthy'); |
| 25 | + assert.deepEqual(_.takeWhile([1,-2,-1,0,1,2], isNeg), [], 'should take elements until a function goes truthy'); |
26 | 26 | }); |
27 | 27 |
|
28 | | - test("dropWhile", function() { |
| 28 | + QUnit.test("dropWhile", function(assert) { |
29 | 29 | var isNeg = function(n) { return n < 0; }; |
30 | 30 |
|
31 | | - deepEqual(_.dropWhile([-2,-1,0,1,2], isNeg), [0,1,2], 'should drop elements until a function goes truthy'); |
32 | | - deepEqual(_.dropWhile([0,1,2], isNeg), [0,1,2], 'should drop elements until a function goes truthy'); |
33 | | - deepEqual(_.dropWhile([-2,-1], isNeg), [], 'should drop elements until a function goes truthy'); |
34 | | - deepEqual(_.dropWhile([1,-2,-1,0,1,2], isNeg), [1,-2,-1,0,1,2], 'should take elements until a function goes truthy'); |
35 | | - deepEqual(_.dropWhile([], isNeg), [], 'should handle empty arrays'); |
| 31 | + assert.deepEqual(_.dropWhile([-2,-1,0,1,2], isNeg), [0,1,2], 'should drop elements until a function goes truthy'); |
| 32 | + assert.deepEqual(_.dropWhile([0,1,2], isNeg), [0,1,2], 'should drop elements until a function goes truthy'); |
| 33 | + assert.deepEqual(_.dropWhile([-2,-1], isNeg), [], 'should drop elements until a function goes truthy'); |
| 34 | + assert.deepEqual(_.dropWhile([1,-2,-1,0,1,2], isNeg), [1,-2,-1,0,1,2], 'should take elements until a function goes truthy'); |
| 35 | + assert.deepEqual(_.dropWhile([], isNeg), [], 'should handle empty arrays'); |
36 | 36 | }); |
37 | 37 |
|
38 | | - test("splitWith", function() { |
| 38 | + QUnit.test("splitWith", function(assert) { |
39 | 39 | var a = [1,2,3,4,5]; |
40 | 40 | var lessEq3p = function(n) { return n <= 3; }; |
41 | 41 | var lessEq3p$ = function(n) { return (n <= 3) ? true : null; }; |
42 | 42 |
|
43 | | - deepEqual(_.splitWith(a, lessEq3p), [[1,2,3], [4,5]], 'should split an array when a function goes false'); |
44 | | - deepEqual(_.splitWith(a, lessEq3p$), [[1,2,3], [4,5]], 'should split an array when a function goes false'); |
45 | | - deepEqual(_.splitWith([], lessEq3p$), [[],[]], 'should split an empty array into two empty arrays'); |
| 43 | + assert.deepEqual(_.splitWith(a, lessEq3p), [[1,2,3], [4,5]], 'should split an array when a function goes false'); |
| 44 | + assert.deepEqual(_.splitWith(a, lessEq3p$), [[1,2,3], [4,5]], 'should split an array when a function goes false'); |
| 45 | + assert.deepEqual(_.splitWith([], lessEq3p$), [[],[]], 'should split an empty array into two empty arrays'); |
46 | 46 | }); |
47 | 47 |
|
48 | | - test("partitionBy", function() { |
| 48 | + QUnit.test("partitionBy", function(assert) { |
49 | 49 | var a = [1, 2, null, false, undefined, 3, 4]; |
50 | 50 |
|
51 | | - deepEqual(_.partitionBy(a, _.truthy), [[1,2], [null, false, undefined], [3,4]], 'should partition an array as a given predicate changes truth sense'); |
| 51 | + assert.deepEqual(_.partitionBy(a, _.truthy), [[1,2], [null, false, undefined], [3,4]], 'should partition an array as a given predicate changes truth sense'); |
52 | 52 | }); |
53 | 53 |
|
54 | | - test("best", function() { |
| 54 | + QUnit.test("best", function(assert) { |
55 | 55 | var a = [1,2,3,4,5]; |
56 | 56 |
|
57 | | - deepEqual(_.best(a, function(x,y) { return x > y; }), 5, 'should identify the best value based on criteria'); |
| 57 | + assert.deepEqual(_.best(a, function(x,y) { return x > y; }), 5, 'should identify the best value based on criteria'); |
58 | 58 | }); |
59 | 59 |
|
60 | | - test("keep", function() { |
| 60 | + QUnit.test("keep", function(assert) { |
61 | 61 | var a = _.range(10); |
62 | 62 | var eveny = function(e) { return (_.isEven(e)) ? e : undefined; }; |
63 | 63 |
|
64 | | - deepEqual(_.keep(a, eveny), [0,2,4,6,8], 'should keep only even numbers in a range tagged with null fails'); |
65 | | - deepEqual(_.keep(a, _.isEven), [true, false, true, false, true, false, true, false, true, false], 'should keep all existy values corresponding to a predicate over a range'); |
| 64 | + assert.deepEqual(_.keep(a, eveny), [0,2,4,6,8], 'should keep only even numbers in a range tagged with null fails'); |
| 65 | + assert.deepEqual(_.keep(a, _.isEven), [true, false, true, false, true, false, true, false, true, false], 'should keep all existy values corresponding to a predicate over a range'); |
66 | 66 | }); |
67 | 67 |
|
68 | | - test("nth", function() { |
| 68 | + QUnit.test("nth", function(assert) { |
69 | 69 | var a = ['a','b','c']; |
70 | 70 | var b = [['a'],['b'],[]]; |
71 | 71 |
|
72 | | - equal(_.nth(a,0), 'a', 'should return the element at a given index into an array'); |
73 | | - equal(_.nth(a,100), undefined, 'should return undefined if out of bounds'); |
74 | | - deepEqual(_.map(b,function(e) { return _.nth(e,0); }), ['a','b',undefined], 'should be usable in _.map'); |
| 72 | + assert.equal(_.nth(a,0), 'a', 'should return the element at a given index into an array'); |
| 73 | + assert.equal(_.nth(a,100), undefined, 'should return undefined if out of bounds'); |
| 74 | + assert.deepEqual(_.map(b,function(e) { return _.nth(e,0); }), ['a','b',undefined], 'should be usable in _.map'); |
75 | 75 | }); |
76 | 76 |
|
77 | | - test("nths", function() { |
| 77 | + QUnit.test("nths", function(assert) { |
78 | 78 | var a = ['a','b','c', 'd']; |
79 | 79 |
|
80 | | - deepEqual(_.nths(a,1), ['b'], 'should return the element at a given index into an array'); |
81 | | - deepEqual(_.nths(a,1,3), ['b', 'd'], 'should return the elements at given indices into an array'); |
82 | | - deepEqual(_.nths(a,1,5,3), ['b', undefined, 'd'], 'should return undefined if out of bounds'); |
| 80 | + assert.deepEqual(_.nths(a,1), ['b'], 'should return the element at a given index into an array'); |
| 81 | + assert.deepEqual(_.nths(a,1,3), ['b', 'd'], 'should return the elements at given indices into an array'); |
| 82 | + assert.deepEqual(_.nths(a,1,5,3), ['b', undefined, 'd'], 'should return undefined if out of bounds'); |
83 | 83 |
|
84 | | - deepEqual(_.nths(a,[1]), ['b'], 'should return the element at a given index into an array'); |
85 | | - deepEqual(_.nths(a,[1,3]), ['b', 'd'], 'should return the elements at given indices into an array'); |
86 | | - deepEqual(_.nths(a,[1,5,3]), ['b', undefined, 'd'], 'should return undefined if out of bounds'); |
| 84 | + assert.deepEqual(_.nths(a,[1]), ['b'], 'should return the element at a given index into an array'); |
| 85 | + assert.deepEqual(_.nths(a,[1,3]), ['b', 'd'], 'should return the elements at given indices into an array'); |
| 86 | + assert.deepEqual(_.nths(a,[1,5,3]), ['b', undefined, 'd'], 'should return undefined if out of bounds'); |
87 | 87 | }); |
88 | 88 |
|
89 | | - test("valuesAt", function() { |
90 | | - equal(_.valuesAt, _.nths, 'valuesAt should be alias for nths'); |
| 89 | + QUnit.test("valuesAt", function(assert) { |
| 90 | + assert.equal(_.valuesAt, _.nths, 'valuesAt should be alias for nths'); |
91 | 91 | }); |
92 | 92 |
|
93 | | - test("binPick", function() { |
| 93 | + QUnit.test("binPick", function(assert) { |
94 | 94 | var a = ['a','b','c', 'd']; |
95 | 95 |
|
96 | | - deepEqual(_.binPick(a, false, true), ['b'], 'should return the element at a given index into an array'); |
97 | | - deepEqual(_.binPick(a, false, true, false, true), ['b', 'd'], 'should return the elements at given indices into an array'); |
98 | | - deepEqual(_.binPick(a, false, true, false, true, true), ['b', 'd', undefined], 'should return undefined if out of bounds'); |
| 96 | + assert.deepEqual(_.binPick(a, false, true), ['b'], 'should return the element at a given index into an array'); |
| 97 | + assert.deepEqual(_.binPick(a, false, true, false, true), ['b', 'd'], 'should return the elements at given indices into an array'); |
| 98 | + assert.deepEqual(_.binPick(a, false, true, false, true, true), ['b', 'd', undefined], 'should return undefined if out of bounds'); |
99 | 99 |
|
100 | | - deepEqual(_.binPick(a, [false, true]), ['b'], 'should return the element at a given index into an array'); |
101 | | - deepEqual(_.binPick(a, [false, true, false, true]), ['b', 'd'], 'should return the elements at given indices into an array'); |
102 | | - deepEqual(_.binPick(a, [false, true, false, true, true]), ['b', 'd', undefined], 'should return undefined if out of bounds'); |
| 100 | + assert.deepEqual(_.binPick(a, [false, true]), ['b'], 'should return the element at a given index into an array'); |
| 101 | + assert.deepEqual(_.binPick(a, [false, true, false, true]), ['b', 'd'], 'should return the elements at given indices into an array'); |
| 102 | + assert.deepEqual(_.binPick(a, [false, true, false, true, true]), ['b', 'd', undefined], 'should return undefined if out of bounds'); |
103 | 103 | }); |
104 | 104 | }); |
105 | 105 |
|
0 commit comments