math-interval-2
Version:
Create math intervals like '(-∞, 100]' and test values
179 lines • 8.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var bound_1 = require("./bound");
describe('Bound', function () {
describe('UpperBound', function () {
describe('compareTo', function () {
it('should return < 0 endpoint is smaller than other if bound type is same', function () {
var a = bound_1.Bound.upperClosedBound(1);
var b = bound_1.Bound.upperClosedBound(2);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return < 0 endpoint is closed smaller than other open', function () {
var a = bound_1.Bound.upperClosedBound(1);
var b = bound_1.Bound.upperOpenBound(2);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return < 0 endpoint is open smaller than other closed', function () {
var a = bound_1.Bound.upperOpenBound(1);
var b = bound_1.Bound.upperClosedBound(2);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return > 0 endpoint is greater than other if bound type is same', function () {
var a = bound_1.Bound.upperClosedBound(2);
var b = bound_1.Bound.upperClosedBound(1);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return > 0 endpoint is closed greater than other open', function () {
var a = bound_1.Bound.upperClosedBound(2);
var b = bound_1.Bound.upperOpenBound(1);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return > 0 endpoint is open greater than other closed', function () {
var a = bound_1.Bound.upperOpenBound(2);
var b = bound_1.Bound.upperClosedBound(1);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return > 0 if close and other open with equal endpoints', function () {
var a = bound_1.Bound.upperClosedBound(1);
var b = bound_1.Bound.upperOpenBound(1);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
});
});
describe('LowerBound', function () {
describe('compareTo', function () {
it('should return > 0 endpoint is smaller than other if bound type is same', function () {
var a = bound_1.Bound.lowerClosedBound(1);
var b = bound_1.Bound.lowerClosedBound(2);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return > 0 endpoint is closed smaller than other open', function () {
var a = bound_1.Bound.lowerClosedBound(1);
var b = bound_1.Bound.lowerOpenBound(2);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return > 0 endpoint is open smaller than other closed', function () {
var a = bound_1.Bound.lowerOpenBound(1);
var b = bound_1.Bound.lowerClosedBound(2);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
it('should return < 0 endpoint is greater than other if bound type is same', function () {
var a = bound_1.Bound.lowerClosedBound(2);
var b = bound_1.Bound.lowerClosedBound(1);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return < 0 endpoint is closed greater than other open', function () {
var a = bound_1.Bound.lowerClosedBound(2);
var b = bound_1.Bound.lowerOpenBound(1);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return < 0 endpoint is open greater than other closed', function () {
var a = bound_1.Bound.lowerOpenBound(2);
var b = bound_1.Bound.lowerClosedBound(1);
expect(a.compareTo(b)).toBeLessThan(0);
});
it('should return > 0 if close and other open with equal endpoints', function () {
var a = bound_1.Bound.lowerClosedBound(1);
var b = bound_1.Bound.lowerOpenBound(1);
expect(a.compareTo(b)).toBeGreaterThan(0);
});
});
});
describe('equals', function () {
it('should be equal if bound typess and endpoints are same', function () {
var a = bound_1.Bound.lowerClosedBound(50);
var b = bound_1.Bound.lowerClosedBound(50);
expect(a.equals(b)).toBe(true);
});
it('should not be equal if bound endpoints are same but types are not', function () {
var a = bound_1.Bound.lowerClosedBound(50);
var b = bound_1.Bound.lowerOpenBound(50);
expect(a.equals(b)).toBe(false);
});
it('should not be equal if bound types are same but endpoints are not', function () {
var a = bound_1.Bound.lowerOpenBound(0);
var b = bound_1.Bound.lowerOpenBound(50);
expect(a.equals(b)).toBe(false);
});
it('should not be equal if bound types and endpoints are not same', function () {
var a = bound_1.Bound.lowerOpenBound(0);
var b = bound_1.Bound.lowerClosedBound(50);
expect(a.equals(b)).toBe(false);
});
it('should be equal if bound types and endpoints are same but one is lower, the other is upper', function () {
var a = bound_1.Bound.upperClosedBound(50);
var b = bound_1.Bound.lowerClosedBound(50);
expect(a.equals(b)).toBe(true);
});
});
describe('LowerClosedBound', function () {
var bound = bound_1.Bound.lowerClosedBound(50);
it('should be close', function () {
expect(bound.closed).toBe(true);
});
describe('test', function () {
it('should return true if equal', function () {
expect(bound.test(50)).toBe(true);
});
it('should return true if greater than', function () {
expect(bound.test(51)).toBe(true);
});
it('should return false if less than', function () {
expect(bound.test(49)).toBe(false);
});
});
});
describe('LowerOpenBound', function () {
var bound = bound_1.Bound.lowerOpenBound(50);
it('should be open', function () {
expect(bound.closed).toBe(false);
});
describe('test', function () {
it('should return false if equal', function () {
expect(bound.test(50)).toBe(false);
});
it('should return true if greater than', function () {
expect(bound.test(51)).toBe(true);
});
it('should return false if less than', function () {
expect(bound.test(49)).toBe(false);
});
});
});
describe('UpperClosedBound', function () {
var bound = bound_1.Bound.upperClosedBound(50);
it('should be close', function () {
expect(bound.closed).toBe(true);
});
describe('test', function () {
it('should return true if equal', function () {
expect(bound.test(50)).toBe(true);
});
it('should return false if greater than', function () {
expect(bound.test(51)).toBe(false);
});
it('should return true if less than', function () {
expect(bound.test(49)).toBe(true);
});
});
});
describe('UpperOpenBound', function () {
var bound = bound_1.Bound.upperOpenBound(50);
it('should be open', function () {
expect(bound.closed).toBe(false);
});
describe('test', function () {
it('should return false if equal', function () {
expect(bound.test(50)).toBe(false);
});
it('should return false if greater than', function () {
expect(bound.test(51)).toBe(false);
});
it('should return true if less than', function () {
expect(bound.test(49)).toBe(true);
});
});
});
});
//# sourceMappingURL=/home/travis/build/harunurhan/math-interval/src/bound.spec.js.map