generated from pabio/github-actions-starter
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9668652
commit 88e26a6
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { checkOverlap } from "./overlap"; | ||
|
||
describe("checkOverlap", () => { | ||
it("partial overlap", () => { | ||
expect(checkOverlap({ start: 14, end: 17 }, { start: 16, end: 19 })).toEqual(1); | ||
}); | ||
|
||
it("partial overlap (opposite)", () => { | ||
expect(checkOverlap({ start: 16, end: 19 }, { start: 14, end: 17 })).toEqual(1); | ||
}); | ||
|
||
it("full overlap", () => { | ||
expect(checkOverlap({ start: 14, end: 17 }, { start: 13, end: 18 })).toEqual(3); | ||
}); | ||
|
||
it("no overlap", () => { | ||
expect(checkOverlap({ start: 14, end: 17 }, { start: 19, end: 21 })).toEqual(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface Range { | ||
start: number; | ||
end: number; | ||
} | ||
|
||
/** | ||
* Get the overlap between two numbers | ||
*/ | ||
export const checkOverlap = (a: Range, b: Range): number => { | ||
const min = a.start < b.start ? a : b; | ||
const max = min.start === a.start && min.end === a.end ? b : a; | ||
if (min.end < max.start) return 0; | ||
return (min.end < max.end ? min.end : max.end) - max.start; | ||
}; |