diff --git a/test/test_rational.cpp b/test/test_rational.cpp new file mode 100644 index 0000000..53d1674 --- /dev/null +++ b/test/test_rational.cpp @@ -0,0 +1,53 @@ +#include "NR.h" + +#include + +static void test() { + /*NR* frac = new NR; + NR frac2(3); + NR frac3(2, 5); + int a, b; + std::cout << "PGCD : entrez deux entiers" << std::endl; + std::cin >> a >> b; + std::cout << PGCD(a, b) << std::endl; + std::cout << "frac : entrez deux entiers" << std::endl; + std::cin >> a >> b; + NR fractest(a, b); + std::cout << fractest << " + " << frac3 << " = " << std::endl; + std::cout << ">> " << (fractest + frac3) << std::endl; + std::cout << ">> " << (fractest + frac3).GetNumerator() << "/" << (fractest + frac3).GetDenominator() << std::endl; + fractest = fractest + frac3; + std::cout << ">> " << fractest << std::endl; + // frac->NRset(2, 4); + NR anotherfrac; + std::cin >> anotherfrac; + std::cout << "Compare " << fractest << " and " << anotherfrac << " : ==? " << (fractest == anotherfrac) << " =? " << (fractest >= anotherfrac) << std::endl; + std::cout << anotherfrac << " - " << *frac << " = " << anotherfrac - *frac << std::endl; + std::cout << anotherfrac << " * " << *frac << " = " << std::endl << ">> " << anotherfrac * *frac << std::endl; + fractest = anotherfrac * *frac; + std::cout << ">> " << fractest << std::endl; + fractest.Reduce(); + std::cout << ">> " << fractest << std::endl; + std::cout << anotherfrac << " / " << frac2 << " = " << anotherfrac / frac2 << std::endl; + NR numNR(2, 4); + NR otherNR(3, 1); + std::cout << numNR << " - " << otherNR << " = " << std::endl; + NR subNR = numNR - otherNR; + std::cout << ">> " << (numNR - otherNR) << std::endl << ">> " << subNR << std::endl; + delete frac;*/ + + NR frac1 {2}; + NR frac2 {1}; + + assert(frac1 != frac2); + + frac2 *= 2; + + assert(frac1 == frac2); +} + +int main(int argc, char** argv) { + test(); + return 0; +} \ No newline at end of file