Skip to content

Commit

Permalink
Updated unit tests (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed May 7, 2024
1 parent 077a0b4 commit 1ad21de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Channel Voice Tests.swift
// MIDIKit • https://github.com/orchetect/MIDIKit
// © 2021-2023 Steffan Andrews • Licensed under MIT License
//

#if shouldTestCurrentPlatform

@testable import MIDIKitCore
import XCTest

final class MIDIEvent_ChannelVoiceTests_Tests: XCTestCase {
// MARK: - Channel Voice Event encoding

func testProgramChange_RawBytes_MIDI1_0() {
XCTAssertEqual(
MIDIEvent.programChange(program: 0x64, bank: .noBankSelect, channel: 10, group: 0).midi1RawBytes(),
[0xCA, 0x64]
)

XCTAssertEqual(
MIDIEvent.programChange(program: 0x64, bank: .bankSelect(msb: 0x10, lsb: 0x00), channel: 10, group: 0).midi1RawBytes(),
[
0xBA, 0x00, 0x10, // Bank Select MSB
0xBA, 0x20, 0x00, // Bank Select LSB
0xCA, 0x64 // Program Change
]
)

XCTAssertEqual(
MIDIEvent.programChange(program: 0x64, bank: .bankSelect(msb: 0x10, lsb: 0x01), channel: 10, group: 0).midi1RawBytes(),
[
0xBA, 0x00, 0x10, // Bank Select MSB
0xBA, 0x20, 0x01, // Bank Select LSB
0xCA, 0x64 // Program Change
]
)
}

// TODO: Add unit tests for other Channel Voice events
}

#endif
17 changes: 15 additions & 2 deletions Tests/MIDIKitIOTests/Parser/MIDI1Parser Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ final class MIDI1Parser_Tests: XCTestCase {

// program change
XCTAssertEqual(
parsedEvents(bytes: [0xCA, 0x20]),
[.programChange(program: 32, channel: 10, group: 0)]
parsedEvents(bytes: [0xCA, 0x40]),
[.programChange(program: 64, channel: 10, group: 0)]
)
// MIDI1Parser does not wait for trailing program change event in order to bundle them in a `.programChange` event.
// It is more idiomatic to MIDI 2.0 than MIDI 1.0.
// TODO: It could be implemented as an optional parser feature in future, similar to MIDI2Parser's RPN/NRPN bundling ability.
XCTAssertEqual(
parsedEvents(bytes: [0xBA, 0x00, 0x10,
0xBA, 0x20, 0x01,
0xCA, 0x40]),
[
.cc(0, value: .midi1(0x10), channel: 10, group: 0x0),
.cc(32, value: .midi1(0x01), channel: 10, group: 0x0),
.programChange(program: 64, /* bank: .bankSelect(msb: 0x10, lsb: 0x01), */ channel: 10, group: 0)
]
)

// channel aftertouch
Expand Down

0 comments on commit 1ad21de

Please sign in to comment.