Beispiel #1
0
/* Verify that the test_ba bitarray has the expected content. Output FAIL or PASS as appropriate for
the Python testing script to parse. Use the testutil_expect() macro to run this function. */
static void testutil_expect_internal(const char *bitstr, size_t flipcount, const char* name) {
  const char *bad = NULL;
  assert(test_ba != NULL);
  size_t sl = strlen(bitstr), i;
  if (sl != bitarray_get_bit_sz(test_ba))
    bad = "bitarray size";
  for (i = 0; i < sl; i++) {
    if (bitarray_get(test_ba, i) != boolfromchar(bitstr[i]))
      bad = "bitarray content";
  }
  if (bad != NULL) {
    bitarray_fprint(stdout, test_ba);
    fprintf(stdout, " expect bits=%s \n", bitstr);
    TEST_FAIL(name, "incorrect %s", bad);
  } else {
    TEST_PASS_WITH_NAME(name);
  }
}
Beispiel #2
0
static void testutil_expect_internal(const char *bitstring,
                                     const char *const func_name,
                                     const int line) {
  // The reason why the test fails.  If the test passes, this will stay
  // NULL.
  const char *bad = NULL;

  assert(test_bitarray != NULL);

  // Check the length of the bit array under test.
  const size_t bitstring_length = strlen(bitstring);
  if (bitstring_length != bitarray_get_bit_sz(test_bitarray)) {
    bad = "bitarray size";
  }

  // Check the content.
  for (size_t i = 0; i < bitstring_length; i++) {
    if (bitarray_get(test_bitarray, i) != boolfromchar(bitstring[i])) {
      bad = "bitarray content";
    }
  }

  // Obtain a string for the actual bitstring.
  const size_t actual_bitstring_length = bitarray_get_bit_sz(test_bitarray);
  char* actual_bitstring = malloc(sizeof(char) * bitstring_length);
  for (size_t i = 0; i < actual_bitstring_length; i++) {
    if (bitarray_get(test_bitarray, i)) {
      actual_bitstring[i] = '1';
    } else {
      actual_bitstring[i] = '0';
    }
  }

  if (bad != NULL) {
    bitarray_fprint(stdout, test_bitarray);
    fprintf(stdout, " expect bits=%s \n", bitstring);
    TEST_FAIL_WITH_NAME(func_name, line, " Incorrect %s.\n    Expected: %s\n    Actual:   %s",
        bad, bitstring, actual_bitstring);
  } else {
    TEST_PASS_WITH_NAME(func_name, line);
  }
  free(actual_bitstring);
}