root/ggpa/TestTools.cpp
| Revision 1, 2.7 kB (checked in by pantley2, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | /* |
| 2 | * TestTools.cpp |
| 3 | * Implementation of the helper functions for tests |
| 4 | */ |
| 5 | |
| 6 | #include "TestTools.h" |
| 7 | |
| 8 | /* |
| 9 | * assert |
| 10 | * No parameters or return type |
| 11 | * |
| 12 | * Ends the program |
| 13 | */ |
| 14 | void assertFunction() { |
| 15 | exit(1); |
| 16 | } |
| 17 | |
| 18 | /* |
| 19 | * assertTrue |
| 20 | * Parameters: value - a boolean value that should be true |
| 21 | * message - a message to send if value is not true |
| 22 | * Return value: none |
| 23 | * If value is not true, then it will send message as an error message, and |
| 24 | * then terminate the program with an error. Otherwise, it will do nothing |
| 25 | */ |
| 26 | void assertTrue(bool value, string message) { |
| 27 | if (!value) { |
| 28 | if (message != "") { |
| 29 | cerr << message << endl; |
| 30 | } |
| 31 | assertFunction(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * assertEquals |
| 37 | * Parameters: value1 - a string that is the first value to compare |
| 38 | * value2 - a string that is the second value to compare |
| 39 | * message - a message to send if the values are not equal |
| 40 | * Return value: none |
| 41 | * If value1 != value2, it will output message as an error message, and then |
| 42 | * send an error containing the two values. Otherwise it will do nothing. |
| 43 | */ |
| 44 | void assertEquals(string value1, string value2, string message) { |
| 45 | if (value1 != value2) { |
| 46 | if (message != "") { |
| 47 | cerr << message << endl; |
| 48 | } |
| 49 | cerr << "\"" << value1 << "\" != \"" << value2 << "\"" << endl; |
| 50 | assertFunction(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * assertEquals |
| 56 | * Parameters: value1 - a int that is the first value to compare |
| 57 | * value2 - a int that is the second value to compare |
| 58 | * message - a message to send if the values are not equal |
| 59 | * Return value: none |
| 60 | * If value1 != value2, it will output message as an error message, and then |
| 61 | * send an error containing the two values. Otherwise it will do nothing. |
| 62 | */ |
| 63 | void assertEquals(int value1, int value2, string message) { |
| 64 | if (value1 != value2) { |
| 65 | if (message != "") { |
| 66 | cerr << message << endl; |
| 67 | } |
| 68 | cerr << value1 << " != " << value2 << "." << endl; |
| 69 | assertFunction(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * assertEquals |
| 75 | * Parameters: value1 - a double that is the first value to compare |
| 76 | * value2 - a double that is the second value to compare |
| 77 | * message - a message to send if the values are not equal |
| 78 | * Return value: none |
| 79 | * If value1 != value2, it will output message as an error message, and then |
| 80 | * send an error containing the two values. Otherwise it will do nothing. |
| 81 | */ |
| 82 | void assertEquals(double value1, double value2, string message) { |
| 83 | if (value1 != value2) { |
| 84 | if (message != "") { |
| 85 | cerr << message << endl; |
| 86 | } |
| 87 | cerr << value1 << " != " << value2 << "." << endl; |
| 88 | assertFunction(); |
| 89 | } |
| 90 | } |
Note: See TracBrowser for help on using the browser.
