Skip to content

Commit e18c71d

Browse files
committed
Improve WASM tests.
1 parent 9c142f5 commit e18c71d

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

kord/src/core/chord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ impl HasKnownChord for Chord {
951951
if modifiers.contains(&Modifier::Flat9) {
952952
return KnownChord::AugmentedDominantFlat9(degree);
953953
}
954-
954+
955955
return KnownChord::AugmentedDominant(degree);
956956
}
957957

kord/src/wasm.rs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,12 @@ mod tests {
11901190
let chord = KordChord::parse("Cm7b5".to_string()).unwrap();
11911191

11921192
let modifiers = chord.modifiers();
1193-
assert!(modifiers.length() > 0, "Should have modifiers");
1193+
// Cm7b5 (half-diminished) has: minor, dominant 7, flat 5
1194+
assert!(modifiers.length() >= 3, "Cm7b5 should have at least 3 modifiers");
11941195

11951196
let extensions = chord.extensions();
1196-
// May or may not have extensions depending on the chord
1197-
assert!(extensions.length() >= 0);
1197+
// Half-diminished chord has no extensions (only modifiers)
1198+
assert_eq!(extensions.length(), 0, "Cm7b5 should have no extensions");
11981199
}
11991200

12001201
#[wasm_bindgen_test]
@@ -1273,9 +1274,9 @@ mod tests {
12731274
fn test_chord_builder_flat5() {
12741275
let chord = KordChord::parse("C".to_string()).unwrap();
12751276
let flat5 = chord.flat5();
1276-
// Verify it has the flat 5 modifier
1277-
let modifiers = flat5.modifiers();
1278-
assert!(modifiers.length() > 0);
1277+
// Verify display shows the flat 5
1278+
let display = flat5.display();
1279+
assert!(display.contains("♭5") || display.contains("b5"), "Flat5 chord should show ♭5 in display: {}", display);
12791280
}
12801281

12811282
#[wasm_bindgen_test]
@@ -1408,7 +1409,7 @@ mod tests {
14081409
let chord = KordChord::parse("C".to_string()).unwrap();
14091410
let sharp13 = chord.sharp13();
14101411
let extensions = sharp13.extensions();
1411-
assert!(extensions.length() > 0, "Should have sharp13 extension");
1412+
assert_eq!(extensions.length(), 1, "Should have exactly 1 extension (sharp13)");
14121413
}
14131414

14141415
#[wasm_bindgen_test]
@@ -1428,8 +1429,8 @@ mod tests {
14281429
let chord = KordChord::parse("C".to_string()).unwrap();
14291430
let notes = chord.chord();
14301431

1431-
// Test that we can iterate the array
1432-
assert!(notes.length() > 0, "Should have notes in array");
1432+
// C major triad has exactly 3 notes
1433+
assert_eq!(notes.length(), 3, "C major should have 3 notes");
14331434

14341435
// Test that we can get individual elements
14351436
let first = notes.get(0);
@@ -1445,7 +1446,7 @@ mod tests {
14451446
assert_eq!(note.name(), "C4");
14461447

14471448
let chord = KordChord::parse("Cmaj7".to_string()).unwrap();
1448-
assert!(chord.display().len() > 0, "Display should return non-empty string");
1449+
assert!(chord.display().contains("maj7"), "Display should contain 'maj7'");
14491450
}
14501451

14511452
#[wasm_bindgen_test]
@@ -1537,7 +1538,7 @@ mod tests {
15371538
// Test with a chord that has extensions
15381539
let complex = KordChord::parse("Csus2".to_string()).unwrap();
15391540
let complex_extensions = complex.extensions();
1540-
assert!(complex_extensions.length() > 0, "Sus2 chord should have extensions");
1541+
assert_eq!(complex_extensions.length(), 1, "Sus2 chord should have exactly 1 extension");
15411542
}
15421543

15431544
#[wasm_bindgen_test]
@@ -1546,7 +1547,8 @@ mod tests {
15461547
let chord = KordChord::parse("Cmaj7#9b13".to_string()).unwrap();
15471548
let notes = chord.chord();
15481549

1549-
assert!(notes.length() > 0, "Complex chord should have notes");
1550+
// Cmaj7#9b13 has: root, 3rd, 5th, 7th, #9, b13 = 6 notes
1551+
assert!(notes.length() >= 5, "Complex chord should have at least 5 notes, got {}", notes.length());
15501552

15511553
// Verify we can access multiple elements
15521554
for i in 0..notes.length() {
@@ -1691,8 +1693,8 @@ mod tests {
16911693
let _root = chord.root();
16921694
let _description = chord.description();
16931695

1694-
// Object should still be valid
1695-
assert!(chord.chord().length() > 0);
1696+
// Object should still be valid with expected note count
1697+
assert_eq!(chord.chord().length(), 3, "C major should still have 3 notes after reuse");
16961698
}
16971699

16981700
#[wasm_bindgen_test]
@@ -2017,14 +2019,16 @@ mod tests {
20172019
fn test_scale_candidates_basic() {
20182020
let chord = KordChord::parse("C".to_string()).unwrap();
20192021
let candidates = chord.scale_candidates();
2020-
assert!(candidates.length() > 0, "Should have scale candidates");
2022+
// C major should have exactly 4 candidates: Ionian, Major Pentatonic, Lydian, Mixolydian
2023+
assert_eq!(candidates.length(), 4, "C major should have 4 scale candidates");
20212024
}
20222025

20232026
#[wasm_bindgen_test]
20242027
fn test_scale_candidates_notes() {
20252028
let chord = KordChord::parse("C".to_string()).unwrap();
20262029
let candidates = chord.scale_candidates();
2027-
assert!(candidates.length() > 0, "Should have candidates");
2030+
// First candidate for C major should be Ionian with 7 notes
2031+
assert_eq!(candidates.length(), 4, "Should have 4 candidates");
20282032
}
20292033

20302034
#[wasm_bindgen_test]
@@ -2045,7 +2049,8 @@ mod tests {
20452049
fn test_scale_candidates_minor_chord() {
20462050
let chord = KordChord::parse("Cm".to_string()).unwrap();
20472051
let candidates = chord.scale_candidates();
2048-
assert!(candidates.length() > 0, "Cm should have candidates");
2052+
// Minor chord has: Aeolian, Minor Pentatonic, Blues, Dorian, Phrygian, Harmonic Minor, Melodic Minor
2053+
assert_eq!(candidates.length(), 7, "Cm should have 7 candidates");
20492054
}
20502055

20512056
#[wasm_bindgen_test]
@@ -2066,14 +2071,17 @@ mod tests {
20662071
fn test_scale_candidates_ranking_order() {
20672072
let chord = KordChord::parse("C".to_string()).unwrap();
20682073
let candidates = chord.scale_candidates();
2069-
assert!(candidates.length() >= 2, "Should have multiple candidates");
2074+
// Ionian (rank 1), Major Pentatonic (rank 2), Lydian (rank 3), Mixolydian (rank 4)
2075+
assert_eq!(candidates.length(), 4, "Should have 4 candidates in ranked order");
20702076
}
20712077

20722078
#[wasm_bindgen_test]
20732079
fn test_scale_candidates_copy() {
20742080
let chord = KordChord::parse("C".to_string()).unwrap();
2075-
let candidates = chord.scale_candidates();
2076-
assert!(candidates.length() > 0, "Should have candidates");
2081+
let candidates1 = chord.scale_candidates();
2082+
let candidates2 = chord.scale_candidates();
2083+
// Multiple calls should return same candidates
2084+
assert_eq!(candidates1.length(), candidates2.length(), "Repeated calls should return same count");
20772085
}
20782086

20792087
#[wasm_bindgen_test]
@@ -2084,21 +2092,24 @@ mod tests {
20842092
let c_candidates = c_chord.scale_candidates();
20852093
let g_candidates = g_chord.scale_candidates();
20862094

2087-
assert!(c_candidates.length() > 0, "C should have candidates");
2088-
assert!(g_candidates.length() > 0, "G should have candidates");
2095+
// Same chord type (major) should have same number of candidates regardless of root
2096+
assert_eq!(c_candidates.length(), g_candidates.length(), "C and G major should have same candidate count");
2097+
assert_eq!(c_candidates.length(), 4, "Major chords should have 4 candidates");
20892098
}
20902099

20912100
#[wasm_bindgen_test]
20922101
fn test_scale_candidates_pentatonic_in_recommendations() {
20932102
let chord = KordChord::parse("C".to_string()).unwrap();
20942103
let candidates = chord.scale_candidates();
2095-
assert!(candidates.length() >= 2, "Should have multiple candidates including pentatonic");
2104+
// Major Pentatonic is rank 2 for major chords
2105+
assert_eq!(candidates.length(), 4, "C major should have 4 candidates including Major Pentatonic");
20962106
}
20972107

20982108
#[wasm_bindgen_test]
20992109
fn test_scale_candidates_blues_in_recommendations() {
21002110
let chord = KordChord::parse("G7".to_string()).unwrap();
21012111
let candidates = chord.scale_candidates();
2102-
assert!(candidates.length() >= 2, "G7 should have multiple candidates including blues");
2112+
// Dominant 7 has: Mixolydian, Blues, Lydian Dominant, Mixolydian b6, Whole Tone, Dim HW, Altered
2113+
assert_eq!(candidates.length(), 7, "G7 should have 7 candidates including Blues");
21032114
}
21042115
}

0 commit comments

Comments
 (0)