Skip to content

Commit

Permalink
chore: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Sep 3, 2024
1 parent 26f4e82 commit afad2eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/invalidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describeVariants(
graphic1.enable.start = '#graphic0.end + 15' // 35

const resolved2 = resolveTimeline(timeline, { time: 0, cache })
expect(resolved2.statistics.resolvingObjectCount).toEqual(1)
expect(resolved2.statistics.resolvingObjectCount).toEqual(2)
expect(resolved2.objects['video'].resolved).toMatchObject({ instances: [{ start: 0, end: 100 }] })
expect(resolved2.objects['graphic0'].resolved).toMatchObject({ instances: [{ start: 10, end: 20 }] })
expect(resolved2.objects['graphic1'].resolved).toMatchObject({ instances: [{ start: 35, end: 50 }] })
Expand Down Expand Up @@ -121,7 +121,7 @@ describeVariants(

const resolved2 = resolveTimeline(timeline, { time: 0, cache })

expect(resolved2.statistics.resolvingObjectCount).toEqual(2)
expect(resolved2.statistics.resolvingObjectCount).toEqual(3)
expect(resolved2.objects['video0'].resolved.instances).toMatchObject([{ start: 20, end: 30 }])
expect(resolved2.objects['graphic0'].resolved.instances).toMatchObject([{ start: 30, end: 40 }])
expect(resolved2.objects['graphic1'].resolved.instances).toHaveLength(0)
Expand Down Expand Up @@ -261,7 +261,7 @@ describeVariants(
timeline.splice(index, 1)

const resolved3 = resolveTimeline(timeline, { time: 0, cache })
expect(resolved3.statistics.resolvingObjectCount).toEqual(1)
expect(resolved3.statistics.resolvingObjectCount).toEqual(2)
expect(resolved3.objects['video0'].resolved).toMatchObject({ instances: [{ start: 0, end: 100 }] })
expect(resolved3.objects['graphic0'].resolved).toMatchObject({ instances: [{ start: 10, end: 20 }] })
expect(resolved3.objects['graphic1'].resolved).toMatchObject({ instances: [{ start: 20, end: 25 }] })
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/performance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('performance', () => {
test(
'performance test, no cache',
() => {
const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, false)
const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, TIMEOUT_TIME, false)
console.log(
`No Cache: Average time of execution: ${round(executionTimeAvg)} ms\n` +
'Worst 5:\n' +
Expand All @@ -29,7 +29,7 @@ describe('performance', () => {
test(
'performance test, with cache',
() => {
const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, true)
const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, TIMEOUT_TIME, true)
console.log(
`With cache: Average time of execution: ${round(executionTimeAvg)} ms\n` +
'Worst 5:\n' +
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const round = (num: number): number => {

export const doPerformanceTest = (
testCount: number,
timeoutTime: number,
useCache: boolean
): {
errorCount: number
Expand All @@ -48,8 +49,13 @@ export const doPerformanceTest = (

const testCountMax = testCount * 2

const startTime = Date.now()
for (let i = 0; i < testCountMax; i++) {
if (executionTimeCount >= testCount) break
const totalDuration = Date.now() - startTime
if (totalDuration >= timeoutTime) {
throw new Error(`Tests took too long (${totalDuration}ms)`)
}

seed++

Expand Down

0 comments on commit afad2eb

Please sign in to comment.