UNPKG

2.48 kBJavaScriptView Raw
1"use strict";
2/**
3 * This file is part of the @egodigital/egoose distribution.
4 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
5 *
6 * @egodigital/egoose is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * @egodigital/egoose is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19const assert = require("assert");
20const mocha_1 = require("mocha");
21const index_1 = require("../index");
22mocha_1.describe('#compareValuesBy()', function () {
23 mocha_1.describe('Object', function () {
24 mocha_1.it('should return a sorted array (ascending)', function () {
25 const ARR = [1, 2, 3, 0, 4].map(x => {
26 return {
27 value: x,
28 };
29 });
30 const RES = ARR.sort((x, y) => {
31 return index_1.compareValuesBy(x, y, i => i.value);
32 });
33 for (let i = 0; i < ARR.length; i++) {
34 const ITEM = RES[i];
35 assert.ok('object' === typeof ITEM);
36 assert.ok('number' === typeof ITEM.value);
37 assert.equal(ITEM.value, i);
38 assert.strictEqual(ITEM.value, i);
39 }
40 });
41 mocha_1.it('should return a sorted array (descending)', function () {
42 const ARR = [1, 2, 3, 0, 4].map(x => {
43 return {
44 value: x,
45 };
46 });
47 const RES = ARR.sort((x, y) => {
48 return index_1.compareValuesBy(y, x, i => i.value);
49 });
50 for (let i = 0; i < ARR.length; i++) {
51 const ITEM = RES[i];
52 assert.ok('object' === typeof ITEM);
53 assert.ok('number' === typeof ITEM.value);
54 assert.equal(ITEM.value, ARR.length - i - 1);
55 assert.strictEqual(ITEM.value, ARR.length - i - 1);
56 }
57 });
58 });
59});
60//# sourceMappingURL=compareValuesBy.js.map
\No newline at end of file