Skip to content

Commit

Permalink
Adjust null checks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Jan 21, 2024
1 parent 313c2af commit 40c3b2d
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions test/audio/MidiTickLookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ describe('MidiTickLookupTest', () => {
return b;
}

function fretOfBeat(beat: Beat | null) {
return beat && beat.notes.length > 0 ? beat.notes[0].fret : -1;
}

function prepareGraceMultiVoice(graceNoteOverlap: number, graceNoteDuration: number): MidiTickLookup {
const lookup = new MidiTickLookup();

Expand Down Expand Up @@ -619,7 +623,7 @@ describe('MidiTickLookupTest', () => {
trackIndexes: number[],
durations: number[],
currentBeatFrets: number[],
nextBeatFrets: (number | null)[],
nextBeatFrets: number[],
skipClean: boolean = false
) {
const buffer = ByteBuffer.fromString(tex);
Expand All @@ -644,15 +648,15 @@ describe('MidiTickLookupTest', () => {

Logger.debug("Test", `Checking index ${i} with tick ${ticks[i]}`)
expect(currentLookup).to.be.ok;
actualIncrementalFrets.push(currentLookup!.beat.notes.length > 0 ? currentLookup!.beat.notes[0].fret : -1);
actualIncrementalNextFrets.push(currentLookup!.nextBeat?.beat?.notes?.[0]?.fret ?? null)
actualIncrementalFrets.push(fretOfBeat(currentLookup!.beat));
actualIncrementalNextFrets.push(fretOfBeat(currentLookup!.nextBeat?.beat ?? null))
actualIncrementalTickDurations.push(currentLookup!.tickDuration)

if (!skipClean) {
const cleanLookup = lookup.findBeat(tracks, ticks[i], null);

actualCleanFrets.push(cleanLookup!.beat.notes.length > 0 ? cleanLookup!.beat.notes[0].fret : -1);
actualCleanNextFrets.push(cleanLookup!.nextBeat?.beat?.notes?.[0]?.fret ?? null)
actualCleanFrets.push(fretOfBeat(cleanLookup!.beat));
actualCleanNextFrets.push(fretOfBeat(cleanLookup!.nextBeat?.beat ?? null))
actualCleanTickDurations.push(cleanLookup!.tickDuration)
}
}
Expand All @@ -673,7 +677,7 @@ describe('MidiTickLookupTest', () => {
function nextBeatSearchTest(trackIndexes: number[],
durations: number[],
currentBeatFrets: number[],
nextBeatFrets: (number | null)[]
nextBeatFrets: number[]
) {
lookupTest(
`
Expand Down Expand Up @@ -709,7 +713,7 @@ describe('MidiTickLookupTest', () => {
],
[
4, 4, 2, 2, 6, 6, 6, 6,
9, 9, 7, 7, null, null, null, null
9, 9, 7, 7, -1, -1, -1, -1
]
)
});
Expand All @@ -727,7 +731,7 @@ describe('MidiTickLookupTest', () => {
],
[
2, 2, 2, 2, 6, 6, 6, 6,
7, 7, 7, 7, null, null, null, null
7, 7, 7, 7, -1, -1, -1, -1
]
)
});
Expand All @@ -751,7 +755,7 @@ describe('MidiTickLookupTest', () => {
],
[
2, 3, 4, 5,
6, 7, 8, null
6, 7, 8, -1
]
)
});
Expand All @@ -775,7 +779,7 @@ describe('MidiTickLookupTest', () => {
],
[
2, 3, 4, 5,
6, 7, 8, null
6, 7, 8, -1
]
)
});
Expand Down Expand Up @@ -814,13 +818,13 @@ describe('MidiTickLookupTest', () => {
4, 4, 4, 4
],
[
2, 2, null, null,
2, 2, -1, -1,

null, null, null, null,
-1, -1, -1, -1,

4, 4, null, null,
4, 4, -1, -1,

null, null, null, null
-1, -1, -1, -1
],
true
)
Expand All @@ -830,7 +834,7 @@ describe('MidiTickLookupTest', () => {
lookupTest(
`
\\ts 2 4
| 1.1.1 |
| 1.1.1
`,
[
// first bar (empty)
Expand All @@ -851,7 +855,7 @@ describe('MidiTickLookupTest', () => {
],
[
1, 1, 1, 1,
null, null, null, null
-1, -1, -1, -1
]
)
});
Expand Down

0 comments on commit 40c3b2d

Please sign in to comment.