Exemple #1
0
char *test_compare()
{
    bit_clear(a, 0, 255);
    bit_clear(b, 0, 255);
    bit_set(a, 5, 99);
    bit_set(b, 5, 99);
    mu_assert(bit_eq(a, b), "bit_eq is wrong.\n");
    mu_assert(bit_leq(a, b), "bit_leq is wrong.\n");
    mu_assert(bit_eq(b, a), "bit_eq is wrong.\n");
    mu_assert(bit_leq(b, a), "bit_leq is wrong.\n");

    bit_clear(a, 5, 5);
    mu_assert(bit_leq(a, b), "bit_leq is wrong.\n");
    mu_assert(bit_lt(a, b), "bit_lt is wrong.\n");
    mu_assert(!bit_leq(b, a), "bit_leq is wrong.\n");
    mu_assert(!bit_lt(b, a), "bit_lt is wrong.\n");

    return NULL;
}
Exemple #2
0
void test_bit(void)
{
  int i;
  void* B = bit_create(10);
  fprintf(stdout, "call function : %s\n", __func__);
  bit_object_show(B);

  fprintf(stdout, "\ntest function - bit_set/bit_get ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < bit_size(B); ++i)
      bit_set(B, i, rand() % 2);

    bit_object_show(B);
    for (i = 0; i < bit_size(B); ++i)
      fprintf(stdout, "\tbit values [%02d] => %d\n", i, bit_get(B, i));
  }

  fprintf(stdout, "\ntest function - bit_clear_range ===>\n");
  {
    bit_clear_range(B, 0, 4);
    bit_object_show(B);
    bit_for_each(B, bit_object_bit_show, NULL);
  }

  fprintf(stdout, "\ntest function - bit_set_range ===>\n");
  {
    bit_set_range(B, 5, 9);
    bit_object_show(B);
    bit_for_each(B, bit_object_bit_show, NULL);
  }

  fprintf(stdout, "\ntest function - bit_not_range ===>\n");
  {
    bit_not_range(B, 0, 9);
    bit_object_show(B);
    bit_for_each(B, bit_object_bit_show, NULL);
  }

  fprintf(stdout, "\ntest function - bit_clear ===>\n");
  {
    bit_clear(B);
    bit_object_show(B);
  }

  fprintf(stdout, "\ntest function - bit_release ===>\n");
  bit_release(&B);
  bit_object_show(B);


  fprintf(stdout, "\ntest function - bit_lt/bit_eq/bit_leq ===>\n");
  {
    void* B1 = bit_create(5);
    void* B2 = bit_create(5);

    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      bit_set(B1, i, rand() % 2);
      bit_set(B2, i, rand() % 2);
    }
    fprintf(stdout, "    B1 object show:\n");
    bit_for_each(B1, bit_object_bit_show, NULL);
    fprintf(stdout, "    B2 object show:\n");
    bit_for_each(B2, bit_object_bit_show, NULL);

    fprintf(stdout, "    B1 < B2 ? '%s'\n", bit_lt(B1, B2) ? "yes" : "no");
    fprintf(stdout, "    B1 = B2 ? '%s'\n", bit_eq(B1, B2) ? "yes" : "no");
    fprintf(stdout, "    B1 <= B2 ? '%s'\n", bit_leq(B1, B2) ? "yes" : "no");

    bit_release(&B1);
    bit_release(&B2);
  }

  fprintf(stdout, "\ntest function - union/inter/minus/diff ===>\n");
  {
    void* B1 = bit_create(5);
    void* B2 = bit_create(5);

    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      bit_set(B1, i, rand() % 2);
      bit_set(B2, i, rand() % 2);
    }
    fprintf(stdout, "    B1 object show:\n");
    bit_for_each(B1, bit_object_bit_show, NULL);
    fprintf(stdout, "    B2 object show:\n");
    bit_for_each(B2, bit_object_bit_show, NULL);

    B = bit_union(B1, B2);
    fprintf(stdout, "    B1 union B2 ->\n");
    bit_for_each(B, bit_object_bit_show, NULL);
    bit_release(&B);

    B = bit_inter(B1, B2);
    fprintf(stdout, "    B1 inter B2 ->\n");
    bit_for_each(B, bit_object_bit_show, NULL);
    bit_release(&B);
    
    B = bit_minus(B1, B2);
    fprintf(stdout, "    B1 minus B2 ->\n");
    bit_for_each(B, bit_object_bit_show, NULL);
    bit_release(&B);

    B = bit_diff(B1, B2);
    fprintf(stdout, "    B1 diff B2 ->\n");
    bit_for_each(B, bit_object_bit_show, NULL);
    bit_release(&B);

    bit_release(&B1);
    bit_release(&B2);
  }
}