UNPKG

@featurevisor/core

Version:

Core package of Featurevisor for Node.js usage

85 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const allocator_1 = require("./allocator"); describe("core: allocator", function () { test("is a function", function () { expect(allocator_1.getAllocation).toBeInstanceOf(Function); expect(allocator_1.getUpdatedAvailableRangesAfterFilling).toBeInstanceOf(Function); }); test("fills a single range fully", function () { const availableRanges = [[0, 100]]; const result = (0, allocator_1.getAllocation)(availableRanges, 100); expect(result).toEqual(availableRanges); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 100); expect(updatedAvailableRanges).toEqual([]); }); test("fills a single range partially", function () { const availableRanges = [[0, 100]]; const result = (0, allocator_1.getAllocation)(availableRanges, 80); expect(result).toEqual([[0, 80]]); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 80); expect(updatedAvailableRanges).toEqual([[80, 100]]); }); test("fills multiple ranges fully", function () { const availableRanges = [ [0, 50], [50, 100], ]; const result = (0, allocator_1.getAllocation)(availableRanges, 100); expect(result).toEqual(availableRanges); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 100); expect(updatedAvailableRanges).toEqual([]); }); test("fills multiple ranges with breaks in between fully", function () { const availableRanges = [ [0, 40], [60, 100], ]; const result = (0, allocator_1.getAllocation)(availableRanges, 80); expect(result).toEqual(availableRanges); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 80); expect(updatedAvailableRanges).toEqual([]); }); test("fills multiple ranges partially", function () { const availableRanges = [ [0, 50], [50, 100], ]; const result = (0, allocator_1.getAllocation)(availableRanges, 80); expect(result).toEqual([ [0, 50], [50, 80], ]); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 80); expect(updatedAvailableRanges).toEqual([[80, 100]]); }); test("fills multiple ranges with breaks in between partially", function () { const availableRanges = [ [0, 40], [60, 100], ]; const result = (0, allocator_1.getAllocation)(availableRanges, 50); expect(result).toEqual([ [0, 40], [60, 70], ]); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 50); expect(updatedAvailableRanges).toEqual([[70, 100]]); }); test("fills multiple ranges with breaks in between partially, with 3 range items", function () { const availableRanges = [ [0, 30], [60, 70], [90, 95], ]; const result = (0, allocator_1.getAllocation)(availableRanges, 42); expect(result).toEqual([ [0, 30], [60, 70], [90, 92], ]); const updatedAvailableRanges = (0, allocator_1.getUpdatedAvailableRangesAfterFilling)(availableRanges, 42); expect(updatedAvailableRanges).toEqual([[92, 95]]); }); }); //# sourceMappingURL=allocator.spec.js.map