-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add exhaustive tests of all timecodes
- Loading branch information
1 parent
c7d1d34
commit cbb9cee
Showing
12 changed files
with
19,691,540 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/node_modules | ||
/dist | ||
/docs | ||
/bin |
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 @@ | ||
#!/bin/bash | ||
|
||
BMXTIMECODE="./bin/bmxtimecode" | ||
OUTDIR="./testdata" | ||
|
||
generate_timecodes() { | ||
local ratename="$1" | ||
local fraction="$2" | ||
local output="$3" | ||
|
||
${BMXTIMECODE} --output "tc-drop" --rate "${fraction}" all | awk '{$1=$1};1' | sed 's/^[^:]*: //' > "${OUTDIR}/tc-all-${ratename}.txt" | ||
} | ||
|
||
generate_timecodes "23_976" "24000/1001" | ||
generate_timecodes "24" "24" | ||
generate_timecodes "29_97" "30000/1001" | ||
generate_timecodes "30" "30" | ||
generate_timecodes "59_94" "60000/1001" | ||
generate_timecodes "60" "60" |
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
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,74 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import readline from 'readline'; | ||
import { Parse } from './parse'; | ||
import { | ||
Rate, | ||
Rate_23_976, | ||
Rate_24, | ||
Rate_29_97, | ||
Rate_30, | ||
Rate_59_94, | ||
Rate_60, | ||
} from './rate'; | ||
import { Timecode } from './timecode'; | ||
|
||
async function runTimecodesTest( | ||
rate: Rate, | ||
filename: string, | ||
maxFrames?: number | ||
) { | ||
const fileStream = fs.createReadStream( | ||
path.resolve(__dirname, '../testdata', filename) | ||
); | ||
const rl = readline.createInterface({ | ||
input: fileStream, | ||
terminal: false, | ||
}); | ||
|
||
let prevTimecode: Timecode | null = null; | ||
let frameIndex = -1; | ||
for await (const line of rl) { | ||
frameIndex++; | ||
if (maxFrames && frameIndex >= maxFrames) break; | ||
if (line.trim() === '') continue; | ||
|
||
// Frame index -> timecode string | ||
const tcFromIndex = new Timecode(frameIndex, rate, rate.drop > 0); | ||
expect(tcFromIndex.toString()).toBe(line); | ||
|
||
// Timecode string -> frameIndex | ||
const tcFromStr = Parse(line, rate); | ||
expect(tcFromStr.frame).toBe(frameIndex); | ||
|
||
// Compare to the previous timecode | ||
if (prevTimecode != null) { | ||
const prevPlusOne = prevTimecode.add(1); | ||
expect(prevPlusOne.toString()).toBe(tcFromStr.toString()); | ||
expect(prevPlusOne.frame).toBe(frameIndex); | ||
} | ||
|
||
prevTimecode = tcFromStr; | ||
} | ||
} | ||
|
||
describe('test all timecodes exhaustively', () => { | ||
test('all timecodes - 23.976', async () => { | ||
await runTimecodesTest(Rate_23_976, 'tc-all-23_976.txt', 10000); | ||
}); | ||
test('all timecodes - 24', async () => { | ||
await runTimecodesTest(Rate_24, 'tc-all-24.txt', 10000); | ||
}); | ||
test('all timecodes - 29.97', async () => { | ||
await runTimecodesTest(Rate_29_97, 'tc-all-29_97.txt', 10000); | ||
}); | ||
test('all timecodes - 30', async () => { | ||
await runTimecodesTest(Rate_30, 'tc-all-30.txt', 10000); | ||
}); | ||
test('all timecodes - 59.94', async () => { | ||
await runTimecodesTest(Rate_59_94, 'tc-all-59_94.txt', 10000); | ||
}); | ||
test('all timecodes - 60', async () => { | ||
await runTimecodesTest(Rate_60, 'tc-all-60.txt', 10000); | ||
}); | ||
}); |
Oops, something went wrong.