11#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2+ #include " NoteGame.hpp"
23#include " ChallengeFactory.hpp"
34#include " Mocks.hpp"
4- #include " NoteGame.hpp"
55#include < doctest/doctest.h>
66#include < thread>
77
@@ -16,37 +16,37 @@ TEST_CASE("NoteGame Flow") {
1616 config.mode = " maj" ;
1717 config.maxChallenges = 2 ;
1818 NoteGame game (transport, midi, factory, config);
19-
19+
2020 transport.waitForClient (); // Simuler client connecté
2121 game.start ();
2222 std::thread gameThread ([&game]() { game.play (); });
23-
23+
2424 // Premier défi
2525 Message msg1 = transport.waitForSentMessage ();
2626 CHECK (msg1.getType () == " note" );
2727 std::string expectedNote = msg1.getField (" note" );
28-
28+
2929 // Simulation de la réponse correcte via MIDI
3030 midi.pushNotes ({expectedNote});
31-
31+
3232 // Vérification du résultat
3333 Message res1 = transport.waitForSentMessage ();
3434 CHECK (res1.getType () == " result" );
3535 CHECK (res1.hasField (" correct" ));
36-
36+
3737 // Signal pour passer au défi suivant
3838 transport.pushIncoming (Message (" ready" ));
39-
39+
4040 // Deuxième défi
4141 Message msg2 = transport.waitForSentMessage ();
4242 CHECK (msg2.getType () == " note" );
4343 expectedNote = msg2.getField (" note" );
4444 midi.pushNotes ({expectedNote});
45-
45+
4646 Message res2 = transport.waitForSentMessage ();
4747 CHECK (res2.getType () == " result" );
4848 CHECK (res2.hasField (" correct" ));
49-
49+
5050 game.stop ();
5151 if (gameThread.joinable ()) gameThread.join ();
5252}
@@ -61,23 +61,23 @@ TEST_CASE("NoteGame Incorrect Answer") {
6161 config.mode = " maj" ;
6262 config.maxChallenges = 1 ;
6363 NoteGame game (transport, midi, factory, config);
64-
64+
6565 transport.waitForClient ();
6666 game.start ();
6767 std::thread gameThread ([&game]() { game.play (); });
68-
68+
6969 Message msg1 = transport.waitForSentMessage ();
7070 std::string expectedNote = msg1.getField (" note" );
71-
71+
7272 // Envoyer note incorrecte
7373 std::string wrongNote = (expectedNote == " c4" ) ? " d4" : " c4" ;
7474 midi.pushNotes ({wrongNote});
75-
75+
7676 Message res1 = transport.waitForSentMessage ();
7777 CHECK (res1.getType () == " result" );
7878 CHECK (res1.hasField (" incorrect" ));
7979 CHECK_FALSE (res1.hasField (" correct" ));
80-
80+
8181 game.stop ();
8282 if (gameThread.joinable ()) gameThread.join ();
8383}
@@ -92,14 +92,14 @@ TEST_CASE("NoteGame Unknown Scale Fallback") {
9292 config.mode = " mode" ;
9393 config.maxChallenges = 1 ;
9494 NoteGame game (transport, midi, factory, config);
95-
95+
9696 transport.waitForClient ();
9797 game.start ();
9898 std::thread gameThread ([&game]() { game.play (); });
99-
99+
100100 Message msg1 = transport.waitForSentMessage ();
101101 CHECK (msg1.getType () == " note" );
102-
102+
103103 game.stop ();
104104 if (gameThread.joinable ()) gameThread.join ();
105105}
@@ -114,29 +114,29 @@ TEST_CASE("NoteGame Multiple Incorrect Notes") {
114114 config.mode = " maj" ;
115115 config.maxChallenges = 1 ;
116116 NoteGame game (transport, midi, factory, config);
117-
117+
118118 transport.waitForClient ();
119119 game.start ();
120120 std::thread gameThread ([&game]() { game.play (); });
121-
121+
122122 Message msg1 = transport.waitForSentMessage ();
123123 std::string expectedNote = msg1.getField (" note" );
124-
124+
125125 // Envoyer plusieurs notes incorrectes
126126 std::vector<std::string> wrongNotes;
127127 if (expectedNote != " c4" ) wrongNotes.push_back (" c4" );
128128 if (expectedNote != " d4" ) wrongNotes.push_back (" d4" );
129129 if (expectedNote != " e4" ) wrongNotes.push_back (" e4" );
130-
130+
131131 midi.pushNotes (wrongNotes);
132-
132+
133133 Message res1 = transport.waitForSentMessage ();
134134 CHECK (res1.getType () == " result" );
135135 CHECK (res1.hasField (" incorrect" ));
136-
136+
137137 std::string incorrect = res1.getField (" incorrect" );
138138 CHECK (incorrect.find (" " ) != std::string::npos);
139-
139+
140140 game.stop ();
141141 if (gameThread.joinable ()) gameThread.join ();
142142}
0 commit comments