Skip to content

Commit b116c90

Browse files
committed
style: format
1 parent 1b08e20 commit b116c90

7 files changed

Lines changed: 49 additions & 39 deletions

File tree

include/ChordGame.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class ChordGame : public IGameMode {
3232
* @param config Configuration du jeu
3333
* @param withInversions true pour mode avec renversements
3434
*/
35-
ChordGame(ITransport& transport, IMidiInput& midi, ChallengeFactory& factory,
36-
const GameConfig& config, bool withInversions = false);
35+
ChordGame(ITransport& transport, IMidiInput& midi,
36+
ChallengeFactory& factory, const GameConfig& config,
37+
bool withInversions = false);
3738

3839
/**
3940
* @brief Démarre le jeu

src/AnswerValidator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ bool AnswerValidator::valider(const std::string& noteJouee,
1717

1818
int AnswerValidator::getNoteValue(std::string noteName) const {
1919
static const std::map<std::string, int> notesMidi = {
20-
{"C", 0}, {"C#", 1}, {"DB", 1}, {"D", 2}, {"D#", 3}, {"EB", 3},
21-
{"E", 4}, {"F", 5}, {"F#", 6}, {"GB", 6}, {"G", 7}, {"G#", 8},
20+
{"C", 0}, {"C#", 1}, {"DB", 1}, {"D", 2}, {"D#", 3}, {"EB", 3},
21+
{"E", 4}, {"F", 5}, {"F#", 6}, {"GB", 6}, {"G", 7}, {"G#", 8},
2222
{"AB", 8}, {"A", 9}, {"A#", 10}, {"BB", 10}, {"B", 11}};
2323

2424
std::transform(noteName.begin(), noteName.end(), noteName.begin(),

src/ChallengeFactory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ ChallengeFactory::generateChord(const std::string& scale,
6060
rootName[0] = std::toupper(rootName[0]);
6161
std::string name = rootName + (mode == "maj" ? " majeur" : " mineur");
6262

63-
std::vector<std::string> chordNotes = {notes[root] + std::to_string(octave),
64-
notes[third] + std::to_string(octave),
65-
notes[fifth] + std::to_string(octave)};
63+
std::vector<std::string> chordNotes = {
64+
notes[root] + std::to_string(octave),
65+
notes[third] + std::to_string(octave),
66+
notes[fifth] + std::to_string(octave)};
6667
return {name, chordNotes};
6768
}
6869

src/ChordGame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ GameResult ChordGame::play() {
6969

7070
// Valider avec AnswerValidator
7171
std::vector<std::string> playedNotesStr;
72-
for (const auto& n : playedNotes) playedNotesStr.push_back(n.toString());
72+
for (const auto& n : playedNotes)
73+
playedNotesStr.push_back(n.toString());
7374

7475
bool isValid = false;
7576
if (withInversions) {

src/NoteGame.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ GameResult NoteGame::play() {
2323
const int maxChallenges = this->config.maxChallenges;
2424

2525
for (int i = 0; i < maxChallenges; ++i) {
26-
std::string targetNoteStr = factory.generateNote(config.scale, config.mode);
26+
std::string targetNoteStr =
27+
factory.generateNote(config.scale, config.mode);
2728
this->challengeId++;
2829

2930
Message challenge("note", {{"note", targetNoteStr},
3031
{"id", std::to_string(this->challengeId)}});
3132
this->transport.send(challenge);
3233

33-
Logger::log("[NoteGame] Défi {} envoyé: {}", this->challengeId, targetNoteStr);
34+
Logger::log("[NoteGame] Défi {} envoyé: {}", this->challengeId,
35+
targetNoteStr);
3436

3537
auto challengeStart = high_resolution_clock::now();
3638
std::vector<Note> playedNotes = this->midi.readNotes();
3739
auto challengeEnd = high_resolution_clock::now();
3840

39-
auto duration = duration_cast<milliseconds>(challengeEnd - challengeStart).count();
41+
auto duration =
42+
duration_cast<milliseconds>(challengeEnd - challengeStart).count();
4043

4144
bool correct = false;
4245
std::string correctNotes;
@@ -65,7 +68,8 @@ GameResult NoteGame::play() {
6568
resultFields["incorrect"] = "none";
6669
Logger::log("[NoteGame] Aucune note jouée");
6770
} else {
68-
Logger::log("[NoteGame] Résultat: correct='{}' incorrect='{}'", correctNotes, incorrectNotes);
71+
Logger::log("[NoteGame] Résultat: correct='{}' incorrect='{}'",
72+
correctNotes, incorrectNotes);
6973
}
7074

7175
if (correct && incorrectNotes.empty() && playedNotes.size() == 1) {
@@ -77,7 +81,8 @@ GameResult NoteGame::play() {
7781
if (i < maxChallenges - 1) {
7882
Message readyMsg = this->transport.receive();
7983
if (readyMsg.getType() != "ready") {
80-
Logger::err("[NoteGame] Attendu 'ready', reçu '{}'", readyMsg.getType());
84+
Logger::err("[NoteGame] Attendu 'ready', reçu '{}'",
85+
readyMsg.getType());
8186
break;
8287
}
8388
}

test/ChallengeFactoryTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
TEST_CASE("ChallengeFactory") {
99
ChallengeFactory gen;
1010

11-
/// Vérifie génération note aléatoire dans gamme Do Majeur (sans altérations)
11+
/// Vérifie génération note aléatoire dans gamme Do Majeur (sans
12+
/// altérations)
1213
SUBCASE("Generate note in Do Majeur") {
1314
std::string note = gen.generateNote("c", "maj");
1415
std::regex pattern("^[a-g][#b]?[0-9]$");
@@ -45,7 +46,8 @@ TEST_CASE("ChallengeFactory") {
4546

4647
/// Vérifie comportement avec paramètres invalides (gamme inconnue)
4748
SUBCASE("Invalid parameters fallback") {
48-
// Devrait fallback sur Do Majeur selon implémentation (au lieu de chaine vide)
49+
// Devrait fallback sur Do Majeur selon implémentation (au lieu de
50+
// chaine vide)
4951
std::string note = gen.generateNote("invalid", "maj");
5052
CHECK(!note.empty());
5153
auto [nom, notes] = gen.generateChord("invalid", "maj");

test/NoteGameTest.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

Comments
 (0)