UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

56 lines 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mocha_1 = require("mocha"); const chai_1 = require("chai"); const immutable_1 = require("immutable"); const toposort_1 = require("../../src/static/toposort"); (0, mocha_1.describe)('topological sort', () => { const n1 = { id: 1n }; const n2 = { id: 2n }; const n3 = { id: 3n }; const n4 = { id: 4n }; const n5 = { id: 5n }; const n11 = { id: 11n }; (0, mocha_1.it)('sorts empty', () => { const { cycles, sorted } = (0, toposort_1.toposort)((0, immutable_1.Map)(), []); chai_1.assert.isEmpty(cycles.toArray()); chai_1.assert.isEmpty(sorted); }); (0, mocha_1.it)('sorts a fork', () => { // 1 uses 3 and 2 const edges = [ [1n, (0, immutable_1.Set)([2n, 3n])], [2n, (0, immutable_1.Set)([3n])], ]; const { cycles, sorted } = (0, toposort_1.toposort)((0, immutable_1.Map)(edges), [n1, n3, n2]); chai_1.assert.isEmpty(cycles.toArray()); chai_1.assert.deepEqual(sorted, [n3, n2, n1]); }); (0, mocha_1.it)('sorts two layers', () => { // 1 uses 3 and 2 // 2 uses 4 // 3 uses 5 // 4 uses 5 const edges = [ [1n, (0, immutable_1.Set)([2n, 3n])], [2n, (0, immutable_1.Set)([4n])], [3n, (0, immutable_1.Set)([5n])], [4n, (0, immutable_1.Set)([5n])], ]; const { cycles, sorted } = (0, toposort_1.toposort)((0, immutable_1.Map)(edges), [n3, n2, n5, n4, n1]); chai_1.assert.isEmpty(cycles.toArray()); chai_1.assert.deepEqual(sorted, [n5, n3, n4, n2, n1]); }); (0, mocha_1.it)('sorts two defs', () => { // 5 uses 1 and 11 // 11 uses 6 and 7 const edges = [ [5n, (0, immutable_1.Set)([1n, 11n])], [11n, (0, immutable_1.Set)([6n, 7n])], ]; const { cycles, sorted } = (0, toposort_1.toposort)((0, immutable_1.Map)(edges), [n5, n11]); chai_1.assert.isEmpty(cycles.toArray()); chai_1.assert.deepEqual(sorted, [n11, n5]); }); }); //# sourceMappingURL=toposort.test.js.map