This repository has been archived on 2025-02-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Pivot/test/test_rational.cpp
Persson-dev b8ee47e267
Some checks failed
Linux arm64 / Build (push) Failing after 8m57s
add very basic NR test
2024-02-25 20:29:10 +01:00

53 lines
1.7 KiB
C++

#include "NR.h"
#include <cassert>
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) << " >=? " << (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;
}