Ejemplo n.º 1
0
} END_TEST

START_TEST (test_2) {
    object *obj = object_list();
    
    fail_unless(object_list_length(obj) == 0, NULL);
    
    object *val;
    val = object_int(1);
    object_list_insert_at(obj, 0, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 1, NULL);
    
    val = object_int(3);
    object_list_insert_at(obj, 1, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 2, NULL);
    
    val = object_int(2);
    object_list_insert_at(obj, 1, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 3, NULL);
    
    object *next = object_copy(obj);
    
    fail_unless(object_list_length(next) == 3, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 2, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 1, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 0, NULL);
    object_free(obj);
    
    obj = next;
    next = object_copy(next);
    
    object_list_remove(obj, 1);
    fail_unless(object_list_length(obj) == 2, NULL);
    object_free(obj);
    
    obj = next;
    
    object_list_remove(obj, 2);
    fail_unless(object_list_length(obj) == 2, NULL);
    object_free(obj);
    
    object_free(obj);
} END_TEST
Ejemplo n.º 2
0
long timeLinearSearch(
    std::size_t Size,
    std::uniform_int_distribution<IntType> &UniformIntDistribution_,
    std::default_random_engine DefaultRandomEngine_) {
  auto L = getRandomList(Size, UniformIntDistribution_, DefaultRandomEngine_);
  auto x = object_int(UniformIntDistribution_(DefaultRandomEngine_));
  return timeAlgorithm([&]() -> void { L.linear_search(x); });
}
Ejemplo n.º 3
0
object_list
getRandomList(std::size_t Size,
              std::uniform_int_distribution<IntType> &UniformIntDistribution_,
              std::default_random_engine &DefaultRandomEngine_) {
  object_list L;
  for (; Size != 0; --Size) {
    L.append(object_int(UniformIntDistribution_(DefaultRandomEngine_)));
  }

  return L;
}
Ejemplo n.º 4
0
long timeBinarySearch(
    std::size_t Size,
    std::uniform_int_distribution<IntType> &UniformIntDistribution_,
    std::default_random_engine DefaultRandomEngine_) {
  auto L = object_list::mergeSort(
      getRandomList(Size, UniformIntDistribution_, DefaultRandomEngine_));
  auto x = object_int(UniformIntDistribution_(DefaultRandomEngine_));
  return timeAlgorithm([&]() -> void {
    auto M = object_list::sort(L);
    M.search(x);
  });
}
Ejemplo n.º 5
0
long timeAmortizedBinarySearch(
    std::size_t Size,
    std::uniform_int_distribution<IntType> &UniformIntDistribution_,
    std::default_random_engine DefaultRandomEngine_, std::size_t Iterations) {
  auto L = getRandomList(Size, UniformIntDistribution_, DefaultRandomEngine_);
  return timeAlgorithm([&]() -> void {
    auto M = object_list::sort(L);

    for (; Iterations != 0; --Iterations) {
      M.search(object_int(UniformIntDistribution_(DefaultRandomEngine_)));
    }
  });
}