Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 11 additions & 2 deletions src/AnswerValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
#include <sys/types.h>
#include <vector>

// 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<unsigned char>(n1.back())))
n1.pop_back();
if (!n2.empty() && std::isdigit(static_cast<unsigned char>(n2.back())))
n2.pop_back();
std::transform(n1.begin(), n1.end(), n1.begin(), ::toupper);
std::transform(n2.begin(), n2.end(), n2.begin(), ::toupper);
Comment on lines +22 to +23
return n1 == n2;
}

int AnswerValidator::getNoteValue(std::string noteName) const {
Expand Down
2 changes: 2 additions & 0 deletions test/AnswerValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/ChallengeFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Loading