UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

69 lines 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const HeightRange_1 = require("../HeightRange"); describe('testing HeightRange', () => { const hr = (a, b) => new HeightRange_1.HeightRange(a, b); test('length', () => { expect(hr(1, 1).length).toBe(1); expect(hr(1, 10).length).toBe(10); expect(hr(1, 0).length).toBe(0); expect(hr(1, -10).length).toBe(0); }); test('copy', () => { expect(hr(4, 8).copy()).toEqual(hr(4, 8)); }); test('intersect', () => { expect(hr(4, 8).intersect(hr(1, 2)).isEmpty).toBe(true); expect(hr(4, 8).intersect(hr(1, 3)).isEmpty).toBe(true); expect(hr(4, 8).intersect(hr(1, 4))).toEqual(hr(4, 4)); expect(hr(4, 8).intersect(hr(1, 7))).toEqual(hr(4, 7)); expect(hr(4, 8).intersect(hr(1, 8))).toEqual(hr(4, 8)); expect(hr(4, 8).intersect(hr(1, 10))).toEqual(hr(4, 8)); expect(hr(4, 8).intersect(hr(4, 10))).toEqual(hr(4, 8)); expect(hr(4, 8).intersect(hr(5, 10))).toEqual(hr(5, 8)); expect(hr(4, 8).intersect(hr(6, 10))).toEqual(hr(6, 8)); expect(hr(4, 8).intersect(hr(7, 10))).toEqual(hr(7, 8)); expect(hr(4, 8).intersect(hr(8, 10))).toEqual(hr(8, 8)); expect(hr(4, 8).intersect(hr(9, 10)).isEmpty).toBe(true); expect(hr(4, 8).intersect(hr(10, 10)).isEmpty).toBe(true); expect(hr(4, -8).intersect(hr(4, 10)).isEmpty).toBe(true); expect(hr(4, -8).intersect(hr(4, -10)).isEmpty).toBe(true); expect(hr(4, 8).intersect(hr(9, -10)).isEmpty).toBe(true); }); test('union', () => { expect(() => hr(4, 8).union(hr(1, 2))).toThrow(); expect(hr(4, 8).union(hr(1, 3))).toEqual(hr(1, 8)); expect(hr(4, 8).union(hr(1, 4))).toEqual(hr(1, 8)); expect(hr(4, 8).union(hr(1, 7))).toEqual(hr(1, 8)); expect(hr(4, 8).union(hr(1, 8))).toEqual(hr(1, 8)); expect(hr(4, 8).union(hr(1, 10))).toEqual(hr(1, 10)); expect(hr(4, 8).union(hr(4, 10))).toEqual(hr(4, 10)); expect(hr(4, 8).union(hr(5, 10))).toEqual(hr(4, 10)); expect(hr(4, 8).union(hr(6, 10))).toEqual(hr(4, 10)); expect(hr(4, 8).union(hr(7, 10))).toEqual(hr(4, 10)); expect(hr(4, 8).union(hr(8, 10))).toEqual(hr(4, 10)); expect(hr(4, 8).union(hr(9, 10))).toEqual(hr(4, 10)); expect(() => hr(4, 8).union(hr(10, 10))).toThrow(); expect(hr(4, -8).union(hr(4, 10))).toEqual(hr(4, 10)); expect(hr(4, -8).union(hr(4, -10)).isEmpty).toBe(true); expect(hr(4, 8).union(hr(9, -10))).toEqual(hr(4, 8)); }); test('subtract', () => { expect(() => hr(4, 8).subtract(hr(5, 7))).toThrow(); expect(hr(4, 8).subtract(hr(1, 3))).toEqual(hr(4, 8)); expect(hr(4, 8).subtract(hr(1, 4))).toEqual(hr(5, 8)); expect(hr(4, 8).subtract(hr(1, 7))).toEqual(hr(8, 8)); expect(hr(4, 8).subtract(hr(1, 8)).isEmpty).toBe(true); expect(hr(4, 8).subtract(hr(1, 10)).isEmpty).toBe(true); expect(hr(4, 8).subtract(hr(4, 10)).isEmpty).toBe(true); expect(hr(4, 8).subtract(hr(5, 10))).toEqual(hr(4, 4)); expect(hr(4, 8).subtract(hr(6, 10))).toEqual(hr(4, 5)); expect(hr(4, 8).subtract(hr(7, 10))).toEqual(hr(4, 6)); expect(hr(4, 8).subtract(hr(8, 10))).toEqual(hr(4, 7)); expect(hr(4, 8).subtract(hr(9, 10))).toEqual(hr(4, 8)); expect(hr(4, -8).subtract(hr(4, 10)).isEmpty).toBe(true); expect(hr(4, -8).subtract(hr(4, -10)).isEmpty).toBe(true); expect(hr(4, 8).subtract(hr(9, -10))).toEqual(hr(4, 8)); }); }); //# sourceMappingURL=HeightRange.test.js.map