Exemple #1
0
static void
scale_prepare_level()
{
  GdkPixbuf *pixmap;
  int show_weight = 0;
  const int default_list_weight[10] = { 1, 2, 2, 5, 5, 10, 10};
  int list_weight[10]= {0};
  int i, tmp[5];

  group_m = goo_canvas_group_new(boardRootItem, NULL);

  switch(gcomprisBoard->level)
    {
    case 1:
    case 2:
      objet_weight = g_random_int_range(5,20);
      for(i=0; i<10; i++)
	list_weight[i] = default_list_weight[i];
      show_weight = gcomprisBoard->level == 1;
      break;
    case 3:
    case 4:
      while(1)
	{
	  for(i=0; i< 5; i++)
	    do
	      tmp[i] = default_list_weight[g_random_int_range(0,10)];
	    while(tmp[i]==0);

	  objet_weight=0;
	  for(i=0; i<5; i++)
	    objet_weight += g_random_int_range(-1,2) * tmp[i];
	  objet_weight = abs(objet_weight);

	  if(!test_addition(objet_weight, tmp, 5))
	    break;
	}
      for(i=0; i<5; i++)
	list_weight[i] = tmp[i];
      show_weight = gcomprisBoard->level == 3;
      break;
    }

  ask_for_answer = !show_weight;
  for(i=0; list_weight[i] ; i++)
    scale_list_add_weight(group_m, list_weight[i], 0);

  pixmap = gc_pixmap_load(imageList[g_random_int_range(0,imageListCount)]);
  scale_list_add_object(group_d, pixmap, objet_weight, -1, show_weight);
  gdk_pixbuf_unref(pixmap);
}
Exemple #2
0
int main(int argc, const char** argv) {

    unsigned long long int seed;

    if (argc < 2) {
        seed = (unsigned long long) std::chrono::system_clock::now().time_since_epoch().count();
    } else {
        seed = std::strtoull(argv[1], nullptr, 10);
    }

    test_failure();
    test_success((uint32_t) seed, (uint32_t) 10000);
    test_addition();
    test_ordering();

    std::cout << "TEST SUCCEEDED" << std::endl;

}
Exemple #3
0
// test if adding elements in table can produce total
static gboolean
test_addition(int total, int *table, int len)
{
  int i;

  if(total == 0)
    return TRUE;

  for(i=0; i<len; i++)
    {
      if(table[i] <= total && table[i] != 0)
        {
	  gboolean result;
	  int cur;
	  cur = table[i];
	  table[i] = 0;
	  result = test_addition(total-cur, table, len);
	  table[i] = cur;
	  if(result)
	    return TRUE;
        }
    }
  return FALSE;
}