Created
March 20, 2011 23:14
-
-
Save deepthawtz/878777 to your computer and use it in GitHub Desktop.
tests for school assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cassert> | |
| using namespace std; | |
| #include "Rational.h" | |
| int main() | |
| { | |
| Rational c(7,3), d(3,9), x; | |
| // test == and != operator | |
| // 2/4 should be equal to 1/2 since they reduce to the same value | |
| Rational r1(2,4), r2(1,2), r3(3,7); | |
| assert(r1 == r2); | |
| // since assert will call abort() if it fails, this next line prints only if the above assertion passes | |
| // the funky chars in that string will output as green in the console (don't know bout Windows though) | |
| cout << "\e[1;32m == operator passed\e[0m" << endl; | |
| assert(r1 != r3); | |
| cout << "\e[1;32m != operator passed\e[0m" << endl; | |
| // test + operator | |
| x = c + d; | |
| Rational addition_result(8,3); | |
| assert(x == addition_result); | |
| cout << "\e[1;32m + operator passed\e[0m" << endl; | |
| // test - operator | |
| x = c - d; | |
| Rational subtraction_result(2,1); | |
| assert(x == subtraction_result); | |
| cout << "\e[1;32m - operator passed\e[0m" << endl; | |
| // test * operator | |
| x = c * d; | |
| Rational multiplication_result(7,9); | |
| assert(x == multiplication_result); | |
| cout << "\e[1;32m * operator passed\e[0m" << endl; | |
| // test / operator | |
| x = c / d; | |
| Rational division_result(7,1); | |
| assert(x == division_result); | |
| cout << "\e[1;32m / operator passed\e[0m" << endl; | |
| // test > and < operators | |
| assert(c > d); | |
| cout << "\e[1;32m > operator passed\e[0m" << endl; | |
| assert(d < c); | |
| cout << "\e[1;32m < operator passed\e[0m" << endl; | |
| // TODO: test << operator | |
| cout << "\e[1;33m TODO: test << operator\e[0m" << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment