pike.git / src / post_modules / CritBit / testsuite.in

version» Context lines:

pike.git/src/post_modules/CritBit/testsuite.in:24:      define(low_test_tree,[[    test_do(add_constant("GET_SAMPLE", lambda() { return all_constants()->THE_SAMPLE; }) )    test_do(add_constant("SET_SAMPLE", lambda(mixed m) { add_constant("THE_SAMPLE", m); }) )    test_do(add_constant("GET_SORTFUN", lambda() { return all_constants()->THE_SORTFUN; }) )    test_do(add_constant("SET_SORTFUN", lambda(mixed m) { add_constant("THE_SORTFUN", m); }) )    test_do(add_constant("GET_TREE", lambda() { return all_constants()->THE_TREE; }) )    test_do(add_constant("SET_TREE", lambda(mixed m) { add_constant("THE_TREE", m); }) )    test_do(add_constant("GET_SORTED_A", lambda() { return all_constants()->THE_SORTED_A; }) )    test_do(add_constant("SET_SORTED_A", lambda(mixed m) { add_constant("THE_SORTED_A", m); }) ) +  test_do(add_constant("TREE_PROGRAM", $1));    test_do([[ -  random_seed(4044); +     SET_SAMPLE( $2 );    SET_SORTFUN( $3 ); -  SET_TREE($1(GET_SAMPLE())); +  SET_TREE(TREE_PROGRAM(GET_SAMPLE()));    SET_SORTED_A($3(indices(GET_SAMPLE())));    ]])    $4    test_do(add_constant("GET_M") )    test_do(add_constant("GET_SAMPLE") )    test_do(add_constant("GET_SORTFUN") )    test_do(add_constant("GET_TREE") )    test_do(add_constant("GET_SORTED_A") )    test_do(add_constant("SET_M") )    test_do(add_constant("SET_SAMPLE") )    test_do(add_constant("SET_SORTFUN") )    test_do(add_constant("SET_TREE") )    test_do(add_constant("SET_SORTED_A") )       test_do(add_constant("THE_M") )    test_do(add_constant("THE_SAMPLE") )    test_do(add_constant("THE_SORTFUN") )    test_do(add_constant("THE_TREE") )    test_do(add_constant("THE_SORTED_A") ) -  +  test_do(add_constant("TREE_PROGRAM") )   ]])      define(test_loop,[[    low_test_tree([[$1]], [[$2]], [[$3]], [[    test_equal((mapping)GET_TREE(), GET_SAMPLE())    test_tree_equal(GET_TREE(), GET_TREE()->get_subtree())    test_tree_equal(GET_TREE(), GET_TREE()->copy())) -  test_tree_equal($1()+GET_TREE(), GET_TREE()) +  test_tree_equal(TREE_PROGRAM()+GET_TREE(), GET_TREE())    test_tree_equal(GET_TREE()+GET_TREE(), GET_TREE()) -  test_tree_equal(GET_TREE()+$1(), GET_TREE())) -  test_tree_equal(GET_TREE()-GET_TREE(), $1()) -  test_tree_equal(GET_TREE()-$1(), GET_TREE())) +  test_tree_equal(GET_TREE()+TREE_PROGRAM(), GET_TREE())) +  test_tree_equal(GET_TREE()-GET_TREE(), TREE_PROGRAM()) +  test_tree_equal(GET_TREE()-TREE_PROGRAM(), GET_TREE()))    test_tree_qual(GET_TREE()[GET_TREE()->first()..GET_TREE()->last()], GET_TREE()))    test_const_loop([[    foreach (GET_SAMPLE(); mixed a; mixed b) {    if (b != GET_TREE()[a])    error("Value mismatch: (%O : %O) vs (%O : %O)\n", a, b, a, GET_TREE()[a]);    }    ]])    test_const_loop([[    if (sizeof(GET_SAMPLE()) != sizeof(GET_TREE()))    error("Size mismatch: %O vs %O\n", sizeof(GET_SAMPLE()), sizeof(GET_TREE()));    ]])    test_const_loop([[    int i;    foreach (tree; mixed key; mixed val) {    mixed nth = GET_TREE()->nth(i++)[0];    if (nth != key)    error("Key mismatch in nth() vs tree order: (%O : %O) vs (%O : %O)\n", i, key, i, nth);    }    ]])    test_const_loop([[ -  +  tree = tree->copy(); +  int i; +  +  for (i = 1; i < sizeof(a); i += 2) m_delete(tree, a[i]); +  +  for (i = 1; i+1 < sizeof(a); i += 2) { +  if (tree->next(a[i]) != a[i+1]) +  error("next(%O) == %O should be %O\n", a[i], tree->next(a[i]), a[i+1]); +  if (tree->previous(a[i]) != a[i-1]) +  error("previous(%O) == %O should be %O\n", a[i], tree->previous(a[i]), a[i-1]); +  } +  ]]) +  test_const_loop([[    mixed t = GET_TREE()->first();    foreach (GET_SORTED_A(); int i; mixed key) {    if (t != key)    error("Key mismatch in range iterate(): (%O : %O) vs (%O : %O)\n", i, t, i, key);    t = GET_TREE()->next(t);    if (GET_SAMPLE()[key] != GET_TREE()[key])    error("Value mismatch in order: (%O : %O) vs (%O : %O)\n", key, GET_SAMPLE()[key], key, GET_TREE()[key]);    mixed nth = GET_TREE()->nth(i)[0];    if (nth != key)    error("Value mismatch in nth(): (%O : %O) vs (%O : %O)\n", i, key, i, nth);
pike.git/src/post_modules/CritBit/testsuite.in:173:    }    ]])    ]])   ]])      define(test_tree, [[    test_loop([[$1]], [[$2]], [[$3]])    test_loop([[$1]], ([]), [[$3]])   ]])    + define(test_tree_program, [[ +  test_loop([[$1]], [[$2]], [[$3]]) +  test_loop([[$1]], ([]), [[$3]]) +  test_loop(class { string foo = "bar"; inherit $1; int b = 2; }, [[$2]], [[$3]]) +  test_loop(class { string foo = "bar"; inherit $1; int b = 2; }, ([ ]), [[$3]]) + ]]) +    test_tree(ADT.CritBit.Tree, [[all_constants()+mkmapping(map(allocate(1000, 1000), random_string), enumerate(1000))]], sort) - test_tree(ADT.CritBit.IntTree, [[mkmapping(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN), enumerate(2100))]], sort) - test_tree(ADT.CritBit.IPv4Tree, [[mkmapping(map(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN), lambda (int i) { + test_tree_program(ADT.CritBit.IntTree, [[mkmapping(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN), enumerate(2100))]], sort) + test_tree_program(ADT.CritBit.IPv4Tree, [[mkmapping(map(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN), lambda (int i) {    return ADT.CritBit.get_ipv4(i, (abs(i) % 51) & 31);   }), enumerate(2100))]], ADT.CritBit.sort_ipv4) - test_tree(ADT.CritBit.FloatTree, [[mkmapping((array(float))(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN)), enumerate(2100))]], sort) - test_tree(ADT.CritBit.DateTree, [[mkmapping(map(enumerate(2000, time()/3000, 1), Function.curry(Calendar.Second)("unix")), enumerate(2000))]], sort) + test_tree_program(ADT.CritBit.FloatTree, [[mkmapping((array(float))(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN)), enumerate(2100))]], sort) + test_tree_program(ADT.CritBit.DateTree, [[mkmapping(map(enumerate(2000, time()/3000, 1), Function.curry(Calendar.Second)("unix")), enumerate(2000))]], sort) + test_tree_program(ADT.CritBit.BigNumTree, [[mkmapping(enumerate(10000, 2*Int.NATIVE_MAX, Int.NATIVE_MAX+1), enumerate(10000))]], sort)    -  +    END_MARKER