|
1 | | -var JSC = require("jscheck"); |
| 1 | +var JSC = require("jscheck"); |
2 | 2 | var getTestUtils = require("../TestUtils.js"); |
| 3 | +var assert = require("chai").assert; |
3 | 4 |
|
4 | 5 | module.exports = function(config) { |
5 | | - var Immutable = config.implementation; |
6 | | - var TestUtils = getTestUtils(Immutable); |
7 | | - var check = TestUtils.check; |
8 | | - |
9 | | - function dummySorter(a, b) { |
10 | | - if(b > a) { |
11 | | - return 1; |
12 | | - } else if(b < a) { |
13 | | - return -1; |
14 | | - } else { |
15 | | - return 0; |
| 6 | + var Immutable = config.implementation; |
| 7 | + var TestUtils = getTestUtils(Immutable); |
| 8 | + var check = TestUtils.check; |
| 9 | + |
| 10 | + function dummySorter(a, b) { |
| 11 | + if(b > a) { |
| 12 | + return 1; |
| 13 | + } else if(b < a) { |
| 14 | + return -1; |
| 15 | + } else { |
| 16 | + return 0; |
| 17 | + } |
16 | 18 | } |
17 | | - } |
18 | 19 |
|
19 | | - describe("#sortBy", function() { |
20 | | - it("produces a sorted immutable array", function() { |
21 | | - check(100, [ JSC.array(JSC.integer(4), JSC.any()) ], function(array) { |
22 | | - var immutable = Immutable(array); |
23 | | - var mutable = array.slice(); |
| 20 | + describe("#sortBy", function() { |
| 21 | + it("produces a sorted immutable array", function() { |
| 22 | + check(100, [JSC.array(JSC.integer(4), JSC.any())], function(array) { |
| 23 | + var immutable = Immutable(array); |
| 24 | + var mutable = array.slice(); |
24 | 25 |
|
25 | | - var resultImmutable = Immutable.sortBy(immutable); |
26 | | - var resultMutable = mutable.slice(); |
27 | | - resultMutable.sort(); |
| 26 | + var resultImmutable = Immutable.sortBy(immutable); |
| 27 | + var resultMutable = mutable.slice(); |
| 28 | + resultMutable.sort(); |
28 | 29 |
|
29 | | - TestUtils.assertJsonEqual(resultImmutable, resultMutable); |
30 | | - }); |
31 | | - }); |
| 30 | + TestUtils.assertJsonEqual(resultImmutable, resultMutable); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it("produces a sorted immutable array when provided with a sorter function", function() { |
| 35 | + check(100, [JSC.array(JSC.integer(4), JSC.any())], function(array) { |
| 36 | + var immutable = Immutable(array); |
| 37 | + var mutable = array.slice(); |
| 38 | + |
| 39 | + var resultImmutable = Immutable.sortBy(immutable, dummySorter); |
| 40 | + var resultMutable = mutable.slice(); |
| 41 | + resultMutable.sort(dummySorter); |
| 42 | + |
| 43 | + TestUtils.assertJsonEqual(resultImmutable, resultMutable); |
| 44 | + }); |
| 45 | + }); |
32 | 46 |
|
33 | | - it("produces a sorted immutable array when provided with a sorter function", function() { |
34 | | - check(100, [ JSC.array(JSC.integer(4), JSC.any()) ], function(array) { |
35 | | - var immutable = Immutable(array); |
36 | | - var mutable = array.slice(); |
| 47 | + it("returns the same array if it is already sorted", function() { |
| 48 | + check(100, [JSC.array(JSC.integer(4), JSC.any())], function(array) { |
| 49 | + var mutable = array.slice().sort(); |
| 50 | + var immutable = Immutable(mutable); |
37 | 51 |
|
38 | | - var resultImmutable = Immutable.sortBy(immutable, dummySorter); |
39 | | - var resultMutable = mutable.slice(); |
40 | | - resultMutable.sort(dummySorter); |
| 52 | + var resultImmutable = Immutable.sortBy(immutable); |
41 | 53 |
|
42 | | - TestUtils.assertJsonEqual(resultImmutable, resultMutable); |
43 | | - }); |
| 54 | + assert.strictEqual(resultImmutable, immutable); |
| 55 | + }); |
| 56 | + }); |
44 | 57 | }); |
45 | | - }); |
46 | 58 | }; |
0 commit comments