Skip to content

Commit 10614f7

Browse files
committed
test more situations still
1 parent 2a99f93 commit 10614f7

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

chord/test_chord_matcher.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,52 @@ TEST_F(MajorTriadTest, CMajorTriadExtraNoteMatchRooted) {
6565
ASSERT_TRUE(chords.empty());
6666
}
6767

68+
TEST_F(MajorTriadTest, ChordNumNotesField) {
69+
// Test that the num_notes field is correctly populated
70+
ns.NoteOn(0);
71+
ns.NoteOn(4);
72+
ns.NoteOn(7);
73+
auto notes = ns.GetBits();
74+
auto chords = cm.MatchRooted(notes, 0, notes.count());
75+
ASSERT_FALSE(chords.empty());
76+
EXPECT_EQ(3, chords[0].num_notes);
77+
}
78+
79+
TEST_F(ChordMatcherTest, MultiplePatternMatching) {
80+
// Test a config with multiple patterns of different sizes
81+
auto config = std::make_unique<chordless::chord::ChordMatcherConfig>();
82+
config->suffix = "test";
83+
84+
// Add a 2-note pattern
85+
chordless::chord::ChordPattern pattern2;
86+
pattern2.num_notes = 2;
87+
pattern2.pattern.set(0);
88+
pattern2.pattern.set(4);
89+
config->patterns.push_back(pattern2);
90+
91+
// Add a 3-note pattern
92+
chordless::chord::ChordPattern pattern3;
93+
pattern3.num_notes = 3;
94+
pattern3.pattern.set(0);
95+
pattern3.pattern.set(4);
96+
pattern3.pattern.set(7);
97+
config->patterns.push_back(pattern3);
98+
99+
cm.SetConfig(std::move(config));
100+
101+
// Test with 2 notes - should match first pattern
102+
ns.NoteOn(0);
103+
ns.NoteOn(4);
104+
auto notes2 = ns.GetBits();
105+
auto chords2 = cm.MatchRooted(notes2, 0, notes2.count());
106+
ASSERT_FALSE(chords2.empty());
107+
EXPECT_EQ(2, chords2[0].num_notes);
108+
109+
// Test with 3 notes - should match second pattern
110+
ns.NoteOn(7);
111+
auto notes3 = ns.GetBits();
112+
auto chords3 = cm.MatchRooted(notes3, 0, notes3.count());
113+
ASSERT_FALSE(chords3.empty());
114+
EXPECT_EQ(3, chords3[0].num_notes);
115+
}
116+

chord/test_chord_observer.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,108 @@ TEST_F(ChordObserverTest, SetBestChordOnlyEnabled) {
264264
EXPECT_EQ(expected, observer.text());
265265
}
266266

267+
TEST_F(ChordObserverTest, SetSharp) {
268+
// Test SetSharp method
269+
observer.SetSharp(true);
270+
271+
note_state.NoteOn(1); // C#
272+
note_state.NoteOn(5); // F
273+
note_state.NoteOn(8); // G#
274+
275+
auto matcher(std::make_unique<chordless::chord::ChordMatcher>());
276+
auto config = std::make_unique<chordless::chord::ChordMatcherConfig>();
277+
config->name = "Major";
278+
config->suffix = "";
279+
chordless::chord::ChordPattern pattern;
280+
pattern.num_notes = 3;
281+
pattern.pattern.set(0);
282+
pattern.pattern.set(4);
283+
pattern.pattern.set(7);
284+
config->patterns.push_back(std::move(pattern));
285+
matcher->SetConfig(std::move(config));
286+
observer.AddMatcher(std::move(matcher));
287+
288+
observer.OnNoteChange();
289+
290+
// Should show C# (with sharp)
291+
EXPECT_TRUE(observer.text().contains("C♯") || observer.text().contains("C#"));
292+
293+
// Now test with flats
294+
observer.SetSharp(false);
295+
observer.OnNoteChange();
296+
297+
// Should show Db (with flat)
298+
EXPECT_TRUE(observer.text().contains("D♭") || observer.text().contains("Db"));
299+
}
300+
301+
TEST_F(ChordObserverTest, SetBestChordOnlyToggle) {
302+
// Test toggling best chord only on and off multiple times
303+
// We'll verify by checking the behavior rather than the private member
304+
305+
note_state.NoteOn(0); // C
306+
note_state.NoteOn(4); // E
307+
note_state.NoteOn(7); // G
308+
note_state.NoteOn(9); // A (makes it C6)
309+
310+
// Create matchers for both C and C6
311+
auto major_config = std::make_unique<chordless::chord::ChordMatcherConfig>();
312+
major_config->suffix = "";
313+
chordless::chord::ChordPattern major_pattern;
314+
major_pattern.num_notes = 3;
315+
major_pattern.pattern.set(0);
316+
major_pattern.pattern.set(4);
317+
major_pattern.pattern.set(7);
318+
major_config->patterns.push_back(std::move(major_pattern));
319+
320+
auto c6_config = std::make_unique<chordless::chord::ChordMatcherConfig>();
321+
c6_config->suffix = "";
322+
chordless::chord::ChordPattern c6_pattern;
323+
c6_pattern.num_notes = 4;
324+
c6_pattern.pattern.set(0);
325+
c6_pattern.pattern.set(4);
326+
c6_pattern.pattern.set(7);
327+
c6_pattern.pattern.set(9);
328+
c6_config->patterns.push_back(std::move(c6_pattern));
329+
330+
auto major_matcher(std::make_unique<chordless::chord::ChordMatcher>());
331+
major_matcher->SetConfig(std::move(major_config));
332+
observer.AddMatcher(std::move(major_matcher));
333+
334+
auto c6_matcher(std::make_unique<chordless::chord::ChordMatcher>());
335+
c6_matcher->SetConfig(std::move(c6_config));
336+
observer.AddMatcher(std::move(c6_matcher));
337+
338+
// Test with best chord only OFF (default)
339+
observer.SetBestChordOnly(false);
340+
observer.OnNoteChange();
341+
QString result1 = observer.text();
342+
EXPECT_TRUE(result1.contains("C")) << "Result: " << result1.toStdString();
343+
EXPECT_TRUE(result1.contains("")) << "Result: " << result1.toStdString();
344+
345+
// Test with best chord only ON
346+
observer.SetBestChordOnly(true);
347+
observer.OnNoteChange();
348+
QString result2 = observer.text();
349+
EXPECT_EQ("C⁶ ", result2);
350+
351+
// Toggle back to OFF
352+
observer.SetBestChordOnly(false);
353+
observer.OnNoteChange();
354+
QString result3 = observer.text();
355+
EXPECT_TRUE(result3.contains("C")) << "Result: " << result3.toStdString();
356+
EXPECT_TRUE(result3.contains("")) << "Result: " << result3.toStdString();
357+
}
358+
359+
TEST_F(ChordObserverTest, EmptyNoteStateWithBestChordOnly) {
360+
observer.SetBestChordOnly(true);
361+
362+
// No notes pressed
363+
observer.OnNoteChange();
364+
365+
EXPECT_EQ("", observer.text());
366+
EXPECT_EQ(1, spy.count());
367+
}
368+
267369
TEST_F(ChordObserverTest, SetBestChordOnlyDisabled) {
268370
observer.SetBestChordOnly(false);
269371

0 commit comments

Comments
 (0)