UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

63 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const mocha_1 = require("mocha"); const maybe_1 = require("@sweet-monads/maybe"); const util_1 = require("../src/util"); (0, mocha_1.describe)('findMap', () => { (0, mocha_1.it)('is none on empty iterable', () => { (0, chai_1.assert)((0, util_1.findMap)(new Map().values(), _ => (0, maybe_1.just)(42)).isNone(), 'should be none on empty iterable'); }); (0, mocha_1.it)('is `just` when a value can be found', () => { const actual = (0, util_1.findMap)(new Map([ ['a', 1], ['b', 2], ['c', 3], ]).values(), n => (n % 2 === 0 ? (0, maybe_1.just)(n) : (0, maybe_1.none)())); chai_1.assert.deepEqual((0, maybe_1.just)(2), actual); }); (0, mocha_1.it)('is `none` when no value can be found', () => { const result = (0, util_1.findMap)(new Map([ ['a', 1], ['b', 2], ['c', 3], ]).values(), n => (n > 3 ? (0, maybe_1.just)(n) : (0, maybe_1.none)())); (0, chai_1.assert)(result.isNone(), 'should be none'); }); }); (0, mocha_1.describe)('insertSorted', () => { (0, mocha_1.it)('can insert into empty array', () => { const array = []; (0, util_1.insertSorted)(array, 42, (a, b) => a - b); chai_1.assert.deepEqual([42], array); }); (0, mocha_1.it)('can insert into sorted array', () => { const array = [1, 3, 5]; (0, util_1.insertSorted)(array, 2, (a, b) => a - b); chai_1.assert.deepEqual([1, 2, 3, 5], array); }); (0, mocha_1.it)('can insert at the beginning of the array', () => { const array = [2, 3, 4]; (0, util_1.insertSorted)(array, 1, (a, b) => a - b); chai_1.assert.deepEqual([1, 2, 3, 4], array); }); (0, mocha_1.it)('can insert at the end of the array', () => { const array = [1, 2, 3]; (0, util_1.insertSorted)(array, 4, (a, b) => a - b); chai_1.assert.deepEqual([1, 2, 3, 4], array); }); (0, mocha_1.it)('can insert at the middle of the array', () => { const array = [1, 3, 4]; (0, util_1.insertSorted)(array, 2, (a, b) => a - b); chai_1.assert.deepEqual([1, 2, 3, 4], array); }); (0, mocha_1.it)('can sort an array of numbers', () => { const array = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]; var sorted = []; for (const n of array) { (0, util_1.insertSorted)(sorted, n, (a, b) => a - b); } chai_1.assert.deepEqual([1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9], sorted); }); }); //# sourceMappingURL=util.test.js.map