Skip to content

Commit

Permalink
feat(lib): add ending test
Browse files Browse the repository at this point in the history
  • Loading branch information
Draeken authored and Thibault committed Nov 25, 2017
1 parent e3fd695 commit d8c5de3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
intersect,
isAfter,
isBefore,
isEnding,
isMeeting,
isOverlapping,
isStarting,
Expand Down Expand Up @@ -66,6 +67,21 @@ const testFnToIntervals = (
t.throws(fn.bind(null, [{ test: 1 }], { test: 1 }), 'Unrecognized interval format');
};

test('will find ending', t => {
const i1 = { start: 1, end: 8 };
const i2 = { start: 0, end: 8 };
const testOutputFn = t.true.bind(t);
testFnToBoolean(i1, i2, isEnding, testOutputFn);
testFnToBoolean(i2, i1, isEnding, testOutputFn);
});

test('will not find ending', t => {
const i1 = { start: 0, end: 5 };
const i2 = { start: 0, end: 8 };
const testOutputFn = t.false.bind(t);
testFnToBoolean(i1, i2, isEnding, testOutputFn);
});

test('will find starting', t => {
const i1 = { start: 0, end: 5 };
const i2 = { start: 0, end: 8 };
Expand Down
20 changes: 20 additions & 0 deletions lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ export function isStarting<T extends interval>(intervalA: T, intervalB?: T): any
}
}

const isEndingGen = ([a]: IntervalSE[], [b]: IntervalSE[]): boolean => {
return a.end === b.end;
};

/**
* Test if one interval is before another.
*/
export function isEnding<T extends interval>(intervalA: T, intervalB: T): boolean;
export function isEnding<T extends interval>(intervalA: T): (intervalB: T) => boolean;
export function isEnding<T extends interval>(intervalA: T, intervalB?: T): any {
switch (arguments.length) {
case 1:
return (tt2: T | T[]): boolean => {
return setupForTwoIntsToBool<T>(isEndingGen)(intervalA, tt2);
};
case 2:
return setupForTwoIntsToBool<T>(isEndingGen)(intervalA, intervalB as T);
}
}

const propFromNthArg = (n: number, propName: string) => pipe(nthArg(n), prop(propName));

const unifyGen = pipe(
Expand Down

0 comments on commit d8c5de3

Please sign in to comment.