@@ -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+
267369TEST_F (ChordObserverTest, SetBestChordOnlyDisabled) {
268370 observer.SetBestChordOnly (false );
269371
0 commit comments