Beispiel #1
0
void	rohan(t_data *data, t_rohan *rohan)
{
  if (data->menu.start == true)
    {
      copy(rohan->temp, rohan->play, rohan, &rohan->pos_play);
      copy_normal(rohan->temp, rohan->quit, &rohan->pos_quit);
    }
  else
    {
      copy(data->menu.scr, rohan->quit, rohan, &rohan->pos_quit);
      copy_normal(rohan->temp, rohan->play, &rohan->pos_play);
    }
  rohan->turn += 1;
  bunny_blit(&rohan->win->buffer, &rohan->temp->clipable, NULL);
}
void test_vector()
{
  vector<string> default_constructor;
  vector<string> size_constructor(20);
  vector<string> list_constructor({ string("hello"), string(" world"), string(" second "), string("test") });

  print(default_constructor);
  print(size_constructor);
  print(list_constructor);


  string pushback_str("this string is being pushed back");
  vector<string> pushback_normal;
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);
  pushback_normal.push_back(pushback_str);

  print(pushback_normal);

  auto check_operators = [](const vector<string>& vec, int32 start, size_t length) {
    assert(vec.size() == length);
    bool error_found = false;
    for (size_t i = 0; i < vec.size(); ++i)
    {
      if (atoi(vec[i].c_str()) != start + i)
      {
        error_found = true;
        printf("Error in pushback or subscript operators, value: %u\n", i);
      }
    }
    if (error_found == false) printf("subscript and pushback operators successful\n");
  };
  auto itostr = [&check_operators](vector<string>& vec, int32 start, int32 length){
    char_t buffer[256];
    for (int32 i = start; i < start + length; ++i)
    {
      vec.push_back(_itoa(i, buffer, 10));
    }

    check_operators(vec, start, length);
  };

  int32 start = -10;
  int32 length = 45;
  vector<string> pushback_rvalue;
  itostr(pushback_rvalue, start, length);
  print(pushback_rvalue);

  //test copy construct

  vector<string> copy_normal(pushback_normal);
  vector<string> assign_normal;
  assign_normal = pushback_normal;
  printf("\ntest copy normal:\n");
  print(copy_normal);

  printf("\ntest assign normal:\n");
  print(assign_normal);

  auto run_test = [](vector<string>& vec, string test_name, void(*callback)(vector<string>&)) {
    printf("\ntest %s:\n", test_name.c_str());
    printf("before:\n");
    print(vec);
    callback(vec);
    printf("after:\n");
    print(vec);
  };

  auto clear = [](vector<string>& vec) { vec.clear(); };
  auto emplace_back = [](vector<string>& vec) { vec.emplace_back("emp1", "emp2", "emp3"); };
  auto reset = [](vector<string>& vec) { vec.reset(); };
  auto reserve200 = [](vector<string>& vec) { vec.reserve(200); };
  auto reserve500 = [](vector<string>& vec) { vec.reserve(500); };

  run_test(pushback_normal, "emplace back", emplace_back);
  run_test(pushback_rvalue, "emplace back", emplace_back);
  run_test(pushback_normal, "reserve200", reserve200);
  run_test(pushback_rvalue, "reserve500", reserve500);
  run_test(pushback_normal, "clear", clear);
  run_test(pushback_rvalue, "clear", clear);
  run_test(pushback_normal, "emplace back", emplace_back);
  run_test(pushback_rvalue, "emplace back", emplace_back);
  run_test(pushback_normal, "reset", reset);
  run_test(pushback_rvalue, "reset", reset);

  run_test(pushback_normal, "reserve200", reserve200);
  run_test(pushback_rvalue, "reserve500", reserve500);
}