Skip to content

Commit

Permalink
fixed unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianBoldt committed Feb 8, 2025
1 parent 0b2085a commit 8bd6b7e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Sources/Tonic/Chord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public struct Chord: Equatable, Codable {
/// - Returns: Roman Numeral notation
public func romanNumeralNotation(in key: Key) -> String? {
let capitalRomanNumerals = ["I", "II", "III", "IV", "V", "VI", "VII"]
if let index = key.primaryTriads.firstIndex(where: { $0 == self }) {
if let index = key.primaryTriads().firstIndex(where: { $0 == self }) {
let romanNumeral = capitalRomanNumerals[index]
switch type {
case .major: return romanNumeral
Expand Down
10 changes: 5 additions & 5 deletions Tests/TonicTests/ChordTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ class ChordTests: XCTestCase {
}

func testRomanNumerals() {
XCTAssertEqual(Key.C.primaryTriads.map { $0.romanNumeralNotation(in: Key.C) ?? "" },
XCTAssertEqual(Key.C.primaryTriads().map { $0.romanNumeralNotation(in: Key.C) ?? "" },
["I", "ii", "iii", "IV", "V", "vi", "vii°"])
XCTAssertEqual(Key.C.primaryTriads.map { $0.romanNumeralNotation(in: Key.Am) ?? "" },
XCTAssertEqual(Key.C.primaryTriads().map { $0.romanNumeralNotation(in: Key.Am) ?? "" },
["III", "iv", "v", "VI", "VII", "i", "ii°"])
XCTAssertEqual(Key.C.primaryTriads.map { $0.romanNumeralNotation(in: Key.G) ?? "" },
XCTAssertEqual(Key.C.primaryTriads().map { $0.romanNumeralNotation(in: Key.G) ?? "" },
["IV", "", "vi", "", "I", "ii", ""])
XCTAssertEqual(Key.Am.primaryTriads.map { $0.romanNumeralNotation(in: Key.Am) ?? "" },
XCTAssertEqual(Key.Am.primaryTriads().map { $0.romanNumeralNotation(in: Key.Am) ?? "" },
["i", "ii°", "III", "iv", "v", "VI", "VII"])
XCTAssertEqual(Key.Am.primaryTriads.map { $0.romanNumeralNotation(in: Key.C) ?? "" },
XCTAssertEqual(Key.Am.primaryTriads().map { $0.romanNumeralNotation(in: Key.C) ?? "" },
["vi", "vii°", "I", "ii", "iii", "IV", "V"])
}

Expand Down
22 changes: 11 additions & 11 deletions Tests/TonicTests/KeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ class KeyTests: XCTestCase {
}

func testKeyPrimaryTriads() {
XCTAssertEqual(Key.C.primaryTriads.map { $0.description },
XCTAssertEqual(Key.C.primaryTriads().map { $0.description },
["C", "Dm", "Em", "F", "G", "Am", ""])
XCTAssertEqual(Key.Am.primaryTriads.map { $0.description },
XCTAssertEqual(Key.Am.primaryTriads().map { $0.description },
["Am", "", "C", "Dm", "Em", "F", "G"])
XCTAssertEqual(Key.G.primaryTriads.map { $0.description },
XCTAssertEqual(Key.G.primaryTriads().map { $0.description },
["G", "Am", "Bm", "C", "D", "Em", "F♯°"])
XCTAssertEqual(Key.Cs.primaryTriads.map { $0.description },
XCTAssertEqual(Key.Cs.primaryTriads().map { $0.description },
["C♯", "D♯m", "E♯m", "F♯", "G♯", "A♯m", "B♯°"])
XCTAssertEqual(Key.Cb.primaryTriads.map { $0.description },
XCTAssertEqual(Key.Cb.primaryTriads().map { $0.description },
["C♭", "D♭m", "E♭m", "F♭", "G♭", "A♭m", "B♭°"])
}

func testScalePrimaryTriads() {
XCTAssertEqual(Key(root: .C, scale: .harmonicMinor).primaryTriads.map { $0.description },
XCTAssertEqual(Key(root: .C, scale: .harmonicMinor).primaryTriads().map { $0.description },
["Cm", "", "E♭⁺", "Fm", "G", "A♭", ""])

XCTAssertEqual(Key(root: .Db, scale: .phrygian).primaryTriads.map { $0.description },
XCTAssertEqual(Key(root: .Db, scale: .phrygian).primaryTriads().map { $0.description },
["D♭m", "E𝄫", "F♭", "G♭m", "A♭°", "B𝄫", "C♭m"])

XCTAssertEqual(Key(root: .Ds, scale: .harmonicMinor).primaryTriads.map { $0.description },
XCTAssertEqual(Key(root: .Ds, scale: .harmonicMinor).primaryTriads().map { $0.description },
["D♯m", "E♯°", "F♯⁺", "G♯m", "A♯", "B", "C𝄪°"])
}

func testKeyChords() {
XCTAssertEqual(Key.G.chords.count, 60) // This should only change if new chord types are added
for triad in Key.G.primaryTriads {
XCTAssert(Key.G.chords.contains(triad))
XCTAssertEqual(Key.G.chords().count, 60) // This should only change if new chord types are added
for triad in Key.G.primaryTriads() {
XCTAssert(Key.G.chords().contains(triad))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/TonicTests/ReadMeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ final class ReadMeTests: XCTestCase {

// What chords are in this key?
func testChordsInKey() {
XCTAssertEqual(Key.Cm.chords.count, 60)
XCTAssertEqual(Key.Cm.chords().count, 60)
}

// What chords in this key contain this note?
func testChordsInKeyContainNote() {
XCTAssertEqual(Key.C.chords.filter { $0.noteClasses.contains(.C) }.count, 36)
XCTAssertEqual(Key.C.chords().filter { $0.noteClasses.contains(.C) }.count, 36)
}

// What notes do these keys have in common?
Expand Down

0 comments on commit 8bd6b7e

Please sign in to comment.