コード例 #1
0
ファイル: tests.c プロジェクト: MITDelian/6.172
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);
}
コード例 #2
0
ファイル: tests.c プロジェクト: MITDelian/6.172
void testutil_require_valid_input(const size_t bit_offset,
                                  const size_t bit_length,
                                  const ssize_t bit_right_shift_amount,
                                  const char* const func_name,
                                  const int line) {
  size_t bitarray_length = bitarray_get_bit_sz(test_bitarray);
  if (bit_offset > bitarray_length || bit_length > bitarray_length ||
      bit_offset + bit_length > bitarray_length) {
    // invalid input
    TEST_FAIL_WITH_NAME(func_name, line, " TEST SUITE ERROR - " \
        "bit_offset + bit_length > bitarray_length");
  }
}
コード例 #3
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);
  }
}
コード例 #4
0
/* Print a string representation of a bitarray. */
static void bitarray_fprint(FILE *f, bitarray_t *ba) {
  size_t i;
  for (i = 0; i < bitarray_get_bit_sz(ba); i++)
    fprintf(f, "%d", bitarray_get(ba, i) ? 1 : 0);
}
コード例 #5
0
ファイル: tests.c プロジェクト: MITDelian/6.172
static void bitarray_fprint(FILE *const stream,
                            const bitarray_t *const bitarray) {
  for (size_t i = 0; i < bitarray_get_bit_sz(bitarray); i++) {
    fprintf(stream, "%d", bitarray_get(bitarray, i) ? 1 : 0);
  }
}