From d8133739279898a5e18cb1b7daf90add4bd720e5 Mon Sep 17 00:00:00 2001 From: jisele Date: Sat, 13 Jun 2026 10:28:12 +0200 Subject: [PATCH 1/2] feat: validation des notes en ignorant l'octave --- include/Logger.hpp | 2 +- src/AnswerValidator.cpp | 10 ++++++++-- test/AnswerValidatorTest.cpp | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) 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..47c4e5b 100644 --- a/src/AnswerValidator.cpp +++ b/src/AnswerValidator.cpp @@ -7,12 +7,18 @@ #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 From d29c31194f238286679943ff53a26e66d988b8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Wed, 17 Jun 2026 00:33:49 +0200 Subject: [PATCH 2/2] style: format --- src/AnswerValidator.cpp | 9 ++++++--- test/ChallengeFactoryTest.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/AnswerValidator.cpp b/src/AnswerValidator.cpp index 47c4e5b..39076e2 100644 --- a/src/AnswerValidator.cpp +++ b/src/AnswerValidator.cpp @@ -7,15 +7,18 @@ #include #include -// Validation d'une seule note jouee par rapport a une note attendue (en ignorant l'octave) +// 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); 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(); + 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; 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); } }