diff --git a/include/Logger.hpp b/include/Logger.hpp index 10f0cca..f248270 100644 --- a/include/Logger.hpp +++ b/include/Logger.hpp @@ -75,7 +75,7 @@ class Logger { // Écrit message dans fichier et dans sortie appropriés std::ofstream file(path, std::ios::app); if (file.is_open()) { - std::println(file, "[{} {}] {}", date(), time(), message); + file << std::format("[{} {}] {}\n", date(), time(), message); std::println(stdout, "{}", message); } else { std::println(stderr, "[Logger] Impossible d'écrire dans fichier"); diff --git a/src/AnswerValidator.cpp b/src/AnswerValidator.cpp index f9934cf..39076e2 100644 --- a/src/AnswerValidator.cpp +++ b/src/AnswerValidator.cpp @@ -7,12 +7,21 @@ #include #include -// Validation d'une seule note jouee par rapport a une note attendue +// Validation d'une seule note jouee par rapport a une note attendue (en +// ignorant l'octave) bool AnswerValidator::valider(const std::string& noteJouee, const std::string& noteAttendue) { Logger::log("[AnswerValidator] Validation note {} = {}", noteJouee, noteAttendue); - return noteJouee == noteAttendue; + std::string n1 = noteJouee; + std::string n2 = noteAttendue; + if (!n1.empty() && std::isdigit(static_cast(n1.back()))) + n1.pop_back(); + if (!n2.empty() && std::isdigit(static_cast(n2.back()))) + n2.pop_back(); + std::transform(n1.begin(), n1.end(), n1.begin(), ::toupper); + std::transform(n2.begin(), n2.end(), n2.begin(), ::toupper); + return n1 == n2; } int AnswerValidator::getNoteValue(std::string noteName) const { diff --git a/test/AnswerValidatorTest.cpp b/test/AnswerValidatorTest.cpp index 3aa871f..353b367 100644 --- a/test/AnswerValidatorTest.cpp +++ b/test/AnswerValidatorTest.cpp @@ -7,8 +7,10 @@ TEST_CASE("AnswerValidator::valider") { AnswerValidator vn; CHECK(vn.valider("c4", "c4")); + CHECK(vn.valider("c4", "c3")); // Différentes octaves CHECK_FALSE(vn.valider("c4", "d4")); CHECK(vn.valider("d#5", "d#5")); + CHECK(vn.valider("d#5", "d#3")); // Différentes octaves } /// Vérifie la validation d'accords sans renversement diff --git a/test/ChallengeFactoryTest.cpp b/test/ChallengeFactoryTest.cpp index fcae05b..8dd06da 100644 --- a/test/ChallengeFactoryTest.cpp +++ b/test/ChallengeFactoryTest.cpp @@ -16,11 +16,11 @@ TEST_CASE("ChallengeFactory") { CHECK(std::regex_match(note, pattern)); // On vérifie qu'il n'y a pas d'altération (# ou b en 2ème position) if (note.size() > 2) { // Cas avec altération ex: c#4 - CHECK(note[1] != '#'); - CHECK(note[1] != 'b'); + CHECK(note[1] != '#'); + CHECK(note[1] != 'b'); } else { - // Si taille 2, format est "c4", donc pas d'altération - CHECK(note.size() == 2); + // Si taille 2, format est "c4", donc pas d'altération + CHECK(note.size() == 2); } }