-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(timespan): improve check for a time contained in a timespan (#787)
In checking whether a time t is contained in an interval (a, b), consider it true only if a <= t < b. Previously this allowed for a <= t <= b, but that is not accurate since timespans are composed of half-open intervals (closed on the left) with a universe of [0, infinity).
- Loading branch information
1 parent
acf8948
commit f5b7783
Showing
2 changed files
with
128 additions
and
73 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 |
---|---|---|
@@ -1,72 +1,127 @@ | ||
import { test, expect } from "@jest/globals"; | ||
import { huge } from "@wowts/math"; | ||
import { newFromArgs } from "./TimeSpan"; | ||
|
||
test("intersectInterval with one interval which is within the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(5, 10); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(5); | ||
expect(result[2]).toEqual(10); | ||
}); | ||
|
||
test("intersectInterval with one interval which overlaps the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(5, 15); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(5); | ||
expect(result[2]).toEqual(10); | ||
}); | ||
|
||
test("intersectInterval with one interval which overlaps the start of the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(-5, 5); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(0); | ||
expect(result[2]).toEqual(5); | ||
}); | ||
|
||
test("intersectInterval with one interval which does not overlap the end", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(11, 15); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); | ||
|
||
test("intersectInterval with one interval which does not overlap the start", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(-5, -1); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); | ||
|
||
test("intersectInterval with nothing", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(1, huge); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); | ||
import { test, expect } from "@jest/globals"; | ||
import { huge } from "@wowts/math"; | ||
import { newFromArgs } from "./TimeSpan"; | ||
|
||
test("HasTime with point to left of interval", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(10, 20); | ||
|
||
// Act | ||
const bool = timeSpan.HasTime(5); | ||
|
||
// Assert | ||
expect(bool).toBe(false); | ||
}); | ||
|
||
test("HasTime with point on left endpoint of interval", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(10, 20); | ||
|
||
// Act | ||
const bool = timeSpan.HasTime(10); | ||
|
||
// Assert | ||
expect(bool).toBe(true); | ||
}); | ||
|
||
test("HasTime with point inside interval", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(10, 20); | ||
|
||
// Act | ||
const bool = timeSpan.HasTime(15); | ||
|
||
// Assert | ||
expect(bool).toBe(true); | ||
}); | ||
|
||
test("HasTime with point on right endpoint of interval", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(10, 20); | ||
|
||
// Act | ||
const bool = timeSpan.HasTime(20); | ||
|
||
// Assert | ||
expect(bool).toBe(false); | ||
}); | ||
|
||
test("HasTime with point to right of interval", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(10, 20); | ||
|
||
// Act | ||
const bool = timeSpan.HasTime(25); | ||
|
||
// Assert | ||
expect(bool).toBe(false); | ||
}); | ||
|
||
test("intersectInterval with one interval which is within the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(5, 10); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(5); | ||
expect(result[2]).toEqual(10); | ||
}); | ||
|
||
test("intersectInterval with one interval which overlaps the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(5, 15); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(5); | ||
expect(result[2]).toEqual(10); | ||
}); | ||
|
||
test("intersectInterval with one interval which overlaps the start of the first", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(-5, 5); | ||
|
||
// Assert | ||
expect(result[1]).toEqual(0); | ||
expect(result[2]).toEqual(5); | ||
}); | ||
|
||
test("intersectInterval with one interval which does not overlap the end", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(11, 15); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); | ||
|
||
test("intersectInterval with one interval which does not overlap the start", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(0, 10); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(-5, -1); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); | ||
|
||
test("intersectInterval with nothing", () => { | ||
// Arrange | ||
const timeSpan = newFromArgs(); | ||
|
||
// Act | ||
const result = timeSpan.IntersectInterval(1, huge); | ||
|
||
// Assert | ||
expect(result[1]).toBeUndefined(); | ||
}); |