Files
toolbox/gcd/src/gcd_test.cpp
2025-03-30 13:48:18 +02:00

38 lines
1.2 KiB
C++

#include <iostream>
#include <cassert>
#include "gcd.hpp"
/**
* @brief Test if a given result is equal of the expected one and log result
*
* @param name of the unit test
* @param expected result of the function call
* @param result of the function
*/
static void Assert(const char* const name, const uint64_t expected, const uint64_t result) noexcept {
if(expected != result){
std::cerr << "For test named " << name << " Expected '" << expected << "' but got '" << result << "' instead\n";
}
}
/**
* @brief Test suite for the gcd output
*/
void gcd_test(void) noexcept {
Assert("gcd null LR", 0, gcd(0, 0));
Assert("gcd null L", 196883, gcd(196883, 0));
Assert("gcd null R", 196883, gcd(0, 196883));
Assert("gcd self", 196883, gcd(196883, 196883));
Assert("gcd Full HD", 120, gcd(1920, 1080));
Assert("gcd monsterfel", 2773, gcd(196883, 194110));
Assert("gcd monsterfel 2", 2773, gcd(194110, 196883));
Assert("gcd monsterful", 4189, gcd(196883, 192694));
Assert("gcd monsterful 2", 4189, gcd(192694, 196883));
}
int32_t main(void){
setlocale(LC_NUMERIC, ""); // Allow proper number display
gcd_test();
return EXIT_SUCCESS;
}