Commit d83a23b2 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Included E6.10 test.

parent 2fb70b6e
Loading
Loading
Loading
Loading
Loading
+31 −7
Original line number Diff line number Diff line
@@ -5,26 +5,50 @@
#define LAB3
#endif

// HELPERS

/**
 * Asserts that [val] is true, and otherwise throws an exception with the [failureReport]
 * @param val The expression whose truth needs to be checked
 * @param failureReport The error message to provide in case of failure
 */
void assertTrue(bool val, std::string failureReport) {
  if (!val)
    throw std::runtime_error(failureReport);
}
void assertFalse(bool val, std::string failureReport) {
  assertTrue(!val,failureReport);
}

// STUBS
#ifdef LAB3
// add lab 3 stubs
void e61();
void e610();
bool same_elements(int a[], int b[], int size);
void p66();
void e74();
void e715();
void e79();
#endif

// TESTS
void testE610() {
  // run the test cases from the book
  int a[]={1,4,9,16,9,7,4,9,11};
  int b[]={11,1,4,9,16,9,7,4,9};
  int c[]={11,11,7,9,16,4,1,4,9};

  assertTrue(same_elements(a,b, 9), "Failed first book test - 1 4 9 16 9 7 4 9 11 should be the same as 1 4 9 16 9 7 4 9 11.");
  assertFalse(same_elements(a,c, 9), "Failed first book test - 1 4 9 16 9 7 4 9 11 should NOT be the same as 11 11 7 9 16 4 1 4 9.");
}

// MAIN
int main() {
#ifdef LAB3
  // lab 3 tests
  e61();
    e610();
  testE610();
  p66();
  e74();
  e715();