void build_table(table_t *test_table, int num_keys) { int probes = -1; printf(" Build table with"); if (TableType == RAND) { printf(" %d random keys\n", num_keys); probes = build_random(test_table, TableSize, num_keys); } else if (TableType == SEQ) { printf(" %d sequential keys\n", num_keys); probes = build_seq(test_table, TableSize, num_keys); } else if (TableType == FOLD) { printf(" %d folded keys\n", num_keys); probes = build_fold(test_table, TableSize, num_keys); } else if (TableType == WORST) { printf(" %d worst keys\n", num_keys); probes = build_worst(test_table, TableSize, num_keys); } else { printf("invalid option for table type\n"); exit(7); } printf(" The average number of probes for a successful search = %g\n", (double) probes/num_keys); if (Verbose) table_debug_print(test_table); int size = table_entries(test_table); assert(size == num_keys); }
/** \brief Test function */ nunit_res_t bitfield_testclass_t::serial_consistency(const nunit_testclass_ftor_t &testclass_ftor) throw() { bitfield_t bitfield; // test serialization of a null NUNIT_ASSERT( is_serial_consistent(bitfield) ); // build a random one bitfield = build_random(42); // test serialization of a nonnull one NUNIT_ASSERT( is_serial_consistent(bitfield) ); // return no error return NUNIT_RES_OK; }
/** \brief Test function */ nunit_res_t bitfield_testclass_t::get_next_set_unset(const nunit_testclass_ftor_t &testclass_ftor) throw() { bitfield_t bitfield1 = build_random(42); bitfield_t bitfield2; // copy bitfield1 to bitfield2 using the bitfield_t.get_next_set bitfield2 = bitfield_t(bitfield1.size()); for(size_t idx = bitfield1.get_next_set(0); idx < bitfield1.size(); idx = bitfield1.get_next_set(idx+1)){ bitfield2.set(idx, true); } // check that the copy is equal NUNIT_ASSERT( bitfield1 == bitfield2 ); // count the number of unset bit size_t nb_unset = 0; for(size_t idx = bitfield1.get_next_unset(0); idx < bitfield1.size(); idx = bitfield1.get_next_unset(idx+1)) nb_unset++; // check that the number of bit set + number of bit unset is equal to the total number of bits NUNIT_ASSERT( bitfield1.nb_set() + nb_unset == bitfield1.size()); // return no error return NUNIT_RES_OK; }