size_t Approximator::test() { POMAGMA_INFO("Testing approximator"); size_t fail_count = 0; fail_count += test_less(); for (auto pair : m_structure.signature().binary_functions()) { fail_count += test_function(pair.first, *pair.second); } for (auto pair : m_structure.signature().symmetric_functions()) { fail_count += test_function(pair.first, *pair.second); } if (fail_count) { POMAGMA_WARN("Failed approximator test"); } else { POMAGMA_INFO("Passed approximator test"); } return fail_count; }
int test_if_code(int lognum) { int ec = true; int retval = true; uint8 op = 0; uint8 not_test = false; uint8 or_test = false; uint16 last_ip = ip; uint8 p[16] = { 0 }; while (retval && !game.quit_prog_now) { if (debug_.enabled && (debug_.logic0 || lognum)) debug_console(lognum, lTEST_MODE, NULL); last_ip = ip; op = *(code + ip++); memmove(p, (code + ip), 16); switch (op) { case 0xFF: /* END IF, TEST true */ goto end_test; case 0xFD: not_test = !not_test; continue; case 0xFC: /* OR */ /* if or_test is ON and we hit 0xFC, end of OR, then * or is STILL false so break. */ if (or_test) { ec = false; retval = false; goto end_test; } or_test = true; continue; case 0x00: /* return true? */ goto end_test; case 0x01: ec = test_equal(p[0], p[1]); if (p[0] == 11) timer_hack++; break; case 0x02: ec = test_equal(p[0], getvar(p[1])); if (p[0] == 11 || p[1] == 11) timer_hack++; break; case 0x03: ec = test_less(p[0], p[1]); if (p[0] == 11) timer_hack++; break; case 0x04: ec = test_less(p[0], getvar(p[1])); if (p[0] == 11 || p[1] == 11) timer_hack++; break; case 0x05: ec = test_greater(p[0], p[1]); if (p[0] == 11) timer_hack++; break; case 0x06: ec = test_greater(p[0], getvar(p[1])); if (p[0] == 11 || p[1] == 11) timer_hack++; break; case 0x07: ec = test_isset(p[0]); break; case 0x08: ec = test_isset(getvar(p[0])); break; case 0x09: ec = test_has(p[0]); break; case 0x0A: ec = test_obj_in_room(p[0], p[1]); break; case 0x0B: ec = test_posn(p[0], p[1], p[2], p[3], p[4]); break; case 0x0C: ec = test_controller(p[0]); break; case 0x0D: ec = test_keypressed(); break; case 0x0E: ec = test_said(p[0], (uint8 *) code + (ip + 1)); ip = last_ip; ip++; /* skip opcode */ ip += p[0] * 2; /* skip num_words * 2 */ ip++; /* skip num_words opcode */ break; case 0x0F: debugC(7, kDebugLevelScripts, "comparing [%s], [%s]", game.strings[p[0]], game.strings[p[1]]); ec = test_compare_strings(p[0], p[1]); break; case 0x10: ec = test_obj_in_box(p[0], p[1], p[2], p[3], p[4]); break; case 0x11: ec = test_obj_centre(p[0], p[1], p[2], p[3], p[4]); break; case 0x12: ec = test_obj_right(p[0], p[1], p[2], p[3], p[4]); break; default: ec = false; goto end_test; } if (op <= 0x12) ip += logic_names_test[op].num_args; /* exchange ec value */ if (not_test) ec = !ec; /* not is only enabled for 1 test command */ not_test = false; if (or_test && ec) { /* a true inside an OR statement passes * ENTIRE statement scan for end of OR */ /* CM: test for opcode < 0xfc changed from 'op' to * '*(code+ip)', to avoid problem with the 0xfd (NOT) * opcode byte. Changed a bad ip += ... ip++ construct. * This should fix the crash with Larry's logic.0 code: * * if ((isset(4) || * !isset(2) || * v30 == 2 || * v30 == 1)) { * goto Label1; * } * * The bytecode is: * ff fc 07 04 fd 07 02 01 1e 02 01 1e 01 fc ff */ /* find end of OR */ while (*(code + ip) != 0xFC) { if (*(code + ip) == 0x0E) { /* said */ ip++; /* cover count + ^words */ ip += 1 + ((*(code + ip)) * 2); continue; } if (*(code + ip) < 0xFC) ip += logic_names_test[*(code + ip)].num_args; ip++; } ip++; or_test = false; retval = true; } else { retval = or_test ? retval || ec : retval && ec; } } end_test: /* if false, scan for end of IP? */ if (retval) ip += 2; else { ip = last_ip; while (*(code + ip) != 0xff) { if (*(code + ip) == 0x0e) { ip++; ip += (*(code + ip)) * 2 + 1; } else if (*(code + ip) < 0xfc) { ip += logic_names_test[*(code + ip)].num_args; ip++; } else { ip++; } } ip++; /* skip over 0xFF */ ip += READ_LE_UINT16(code + ip) + 2; } if (debug_.enabled && (debug_.logic0 || lognum)) debug_console(lognum, 0xFF, retval ? "=true" : "=false"); return retval; }
void test_all_less() { test_less(nan, nan, zero, "nan < nan"); test_less(nan, nannan, zero, "nan < nannan"); test_less(nan, zero, zero, "nan < zero"); test_less(nannan, nan, zero, "nannan < nan"); test_less(nannan, nannan, zero, "nannan < nannan"); test_less(nannan, one, zero, "nannan < 1"); test_less(zero, nan, one, "zero < nan"); test_less(zero, nannan, one, "0 < nannan"); test_less(zero, zip, zero, "zero < zip"); test_less(zero, minnum, one, "zero < minnum"); test_less(zero, one, one, "zero < one"); test_less(zip, zero, zero, "zip < zero"); test_less(zip, zip, zero, "zip < zip"); test_less(one, negative_one, zero, "1 < -1"); test_less(two, two, zero, "2 < 2"); test_less(two, dec64_new(2, -16), zero, "2 < 2e-16"); test_less(three, pi, one, "3 < pi"); test_less(pi, three, zero, "pi < 3"); test_less(maxint, maxnum, one, "maxint < maxnum"); test_less(negative_maxint, maxint, one, "-maxint < maxint"); test_less(negative_maxint, negative_one, one, "-maxint < -1"); test_less(maxnum, nan, one, "maxnum < nan"); }
int t_map() { c_map map; c_map_create(&map, int_comparer); assert(__c_rb_tree_verify(map._l)); printf("0. test create with insert unique\n"); create_with_insert_unique(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n1. test clear\n"); test_clear(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n2. test size and empty\n"); test_size_empty(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n3. test create with insert equal\n"); c_map_clear(&map); create_with_insert_equal(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n4. test swap\n"); create_with_insert_unique(&map); test_swap(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n5. test create with insert unique1\n"); create_with_insert_unique1(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n6. test create with insert equal1\n"); c_map_clear(&map); create_with_insert_equal1(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n7. test create with insert unique2\n"); c_map_clear(&map); create_with_insert_unique2(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n8. test create with insert equal2\n"); c_map_clear(&map); create_with_insert_equal2(&map); print_map(&map); rprint_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n9. test erase\n"); c_map_clear(&map); create_with_insert_unique(&map); test_erase(&map); create_with_insert_unique(&map); test_reverse_erase(&map); print_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n10. test find and erase\n"); c_map_clear(&map); printf("* test_find_erase:\n"); create_with_insert_unique(&map); print_map(&map); test_find_erase(&map); print_map(&map); printf("* test_reverse_find_erase:\n"); create_with_insert_unique(&map); print_map(&map); test_reverse_find_erase(&map); print_map(&map); assert(__c_rb_tree_verify(map._l)); printf("\n\n11. test count:\n"); // 'lower_bound' 'upper_bound' 'equal_range' used create_with_insert_unique(&map); test_count(&map); printf("\n\n12. test less:\n"); test_less(); printf("\n\n13. test equal:\n"); test_equal(); printf("\n\n14. test at:\n"); test_at(); c_map_destroy(&map); printf("\n\nfinish testing map!\n"); return 0; }