Пример #1
0
int main()
{
  int i;

  for (i = 0; i < 256; i++)
    chartest[i].c = i;
  chartest[0].c = 0;  /* chartest-done */

  Fun1(foo1);	
  Fun2(foo2);	
  Fun3(foo3);	
  Fun4(foo4);	
  Fun5(foo5);	
  Fun6(foo6);	
  Fun7(foo7);	
  Fun8(foo8);	
  Fun9(foo9);	
  Fun10(foo10);
  Fun11(foo11);
  Fun12(foo12);
  Fun13(foo13);
  Fun14(foo14);
  Fun15(foo15);
  Fun16(foo16);
  Fun17(foo17);
  Fun18(foo18);

  /* An (almost-)infinite loop that first clears all the variables and then
     calls each function.  This "hack" is to make testing random
     functions easier - "advance funN" is guaranteed to have always
     been preceded by a global variable clearing zed call.
     We don't let this run forever in case gdb crashes while testing,
     we don't want to be left eating all cpu on the user's system.  */

  for (i = 0; i < 1000000; ++i)
    {
      zed ();
      L1  = fun1();	
      L2  = fun2();	
      L3  = fun3();	
      L4  = fun4();	
      L5  = fun5();	
      L6  = fun6();	
      L7  = fun7();	
      L8  = fun8();	
      L9  = fun9();	
      L10 = fun10();
      L11 = fun11();
      L12 = fun12();
      L13 = fun13();
      L14 = fun14();
      L15 = fun15();
      L16 = fun16();
      L17 = fun17();
      L18 = fun18();
    }

  return 0;
}
Пример #2
0
void test1 () {
    struct V {
        float x = 1.0f;
        float GetX() const { return x; } 
        V() {}
    } const v;
    Class c;
    const Class cc;
    Fun< int (int) >   fun0;
    Fun< int (int) >   fun1(&Twice);  
    Fun< int (int) >   fun2(&Class::Twice);
    Fun< int () >      fun3(&VoidParam);
    Fun< int () >      fun4(&Class::VoidParam);
    Fun< int () >      fun5(&Class::VoidParamConst);
    Fun< void(int&) >  fun6(&Class::Void);
    Fun< int (int) >   fun7((Functor()));
    auto               fun8(RetFun());
    Fun< float (int, int) > fun9([=](int i, int j) {return float(i/j);});
    Fun< float (int, int) > fun10(fun9);
    Fun< float () > fun11([v](){return v.GetX();});
    Fun< void() > vd;

    try { 
         fun0(9); //must throw
         assert(false);
    } catch(...) {}
    fun0 = fun1;
    assert(fun0(2)    == fun1(2));
    assert(fun1(2)    ==  4);
    assert(fun2(c, 3) ==  6);
    assert(fun5(cc)   ==  2);
    assert(fun7(6)    == 18);
    assert(fun8(7)    == 21);
    assert(fun9(10,4) == float(10/4));
    assert(fun10(20, 8) == fun9(20, 8));
    assert(fun11() == 1.0f);
    //void return type
    int i = 0;
    fun6(c, i);
    assert(i == 1234);
}
Пример #3
0
void phase_6(char *input)
{
#if defined(PROBLEM)
    listNode *start = &node1;
    listNode *p;
    int indices[6];
    listNode *pointers[6];
    int i, j;

    read_six_numbers(input, indices);

    /* Check the range of the indices and whether or not any repeat */
    for (i = 0; i < 6; i++) {
	if ((indices[i] < 1) || (indices[i] > 6))
	    explode_bomb();
	
	for (j = i + 1; j < 6; j++) {
	    if (indices[i] == indices[j])
		explode_bomb();
	}
    }

    /* Reverse the permutation */
    for (i = 0; i < 6; i++) {
	indices[i] = 7 - indices[i];
    }

    /* Rearrange the list according to the user input */
    for (i = 0; i < 6; i++) {
	p = start;
	for (j = 1; j < indices[i]; j++)
	    p = p -> next;
	pointers[i] = p;
    }

    start = pointers[0];
    p = start;

    for (i = 1; i < 6; i++) {
	p->next = pointers[i];
	p = p->next;
    }
    p->next = NULL;

    /* Now see if the list is sorted in descending order*/
    p = start;
    for (i = 0; i < 5; i++) {
	if (p->value < p->next->value)
	    explode_bomb();
	
	p = p->next;
    }
#elif defined(SOLUTION)
    listNode *start = &node1;
    listNode *p;

    /* sort */
    start = fun6(start);

    /* emit the (inverted) node indices of the sorted list */
    p = start;
    while (p) {
	printf("%d ", 7 - p->index);
	p = p->next;
    }
    printf("\n");
#else
    invalid_phase("6b");
#endif
}
Пример #4
0
int fun5() {
	set_bp();
	return fun6();
}