Exemple #1
0
void TEST_HashFunctions() {
  ASSERT_EQ(simple_hash::hash("abcd"), simple_hash::hash("abcd"));
  ASSERT_NEQ(simple_hash::hash("a"), simple_hash::hash("b"));
  ASSERT_EQ(normal_hash::hash("abcd"), normal_hash::hash("abcd"));
  ASSERT_NEQ(normal_hash::hash("a"), normal_hash::hash("b"));
  ASSERT_EQ(complex_hash::hash("abcd"), complex_hash::hash("abcd"));
  ASSERT_NEQ(complex_hash::hash("a"), complex_hash::hash("b"));
}
    void rx_new_generation(uint32_t gen, uint32_t gen_size, uint32_t symbol_size)
    {
        ASSERT_LTE(gen_size, rx_max_gen_size);
        ASSERT_LTE(symbol_size, rx_max_symbol_size);
        ASSERT_NEQ(gen_size, 0);
        ASSERT_NEQ(symbol_size, 0);

        decoder_factory.set_symbols(gen_size);
        decoder_factory.set_symbol_size(symbol_size);
        decoder = decoder_factory.build();
        rx_gen = gen;
        rx_gen_size = gen_size;
        rx_symbol_size = symbol_size;
        rx_delivered_symbols = 0;
#if defined(VERBOSE) || defined(KODO_VERBOSE)
        printf("New RX generation, gen=%u, gen_size=%u, symbols_size=%u\n", rx_gen, rx_gen_size, rx_symbol_size);
#endif
    }
Exemple #3
0
    void rx_deliver_next_pkt(p_pkt_buffer& buf)
    {
        ASSERT_NEQ(rx_pkt_queue.count(last_fw_id+1), 0);

        buf->clear();
        ++last_fw_id;
        buf = rx_pkt_queue[last_fw_id];
        rx_pkt_queue.erase(last_fw_id);
#ifdef VERBOSE
        printf("Delivering pkt of %lu bytes and id %u\n", buf->len, buf->id);
#endif
    }
Exemple #4
0
TEST(macro_ASSERT_NEQ, string_objects_test_out_not_equal)
{
  std::string s1("foo");
  std::string s2("bar");
  ASSERT_NEQ(s1, s2);
}
Exemple #5
0
    TEST_EX(::selftest, _ResultSuite, _ResultCorrect)
    {
        // Test correct initial result
        auto iter1 = getResult().getAssertions();
        EXPECT_EQ(iter1.begin(), iter1.end());
        EXPECT(getResult());
        EXPECT(getResult().succeeded());
        EXPECT_EQ(getResult().getFirstFailure(), nullptr);
        EXPECT_EQ(getResult().getFinalFailure(), nullptr);

        // Add a failed assertion
        EXPECT(false);
        ASSERT_NEQ(getResult().getFinalFailure(), nullptr);
        const Assertion* fail1 = getResult().getFinalFailure();

        // Test that result now indicates failure
        EXPECT(!getResult());
        EXPECT(!getResult().succeeded());
        EXPECT_NEQ(getResult().getFirstFailure(), nullptr);
        EXPECT_NEQ(getResult().getFinalFailure(), nullptr);
        EXPECT_EQ(getResult().getFirstFailure(), getResult().getFinalFailure());

        // Test assertion iteration
        auto iter2 = getResult().getAssertions();
        {
            auto current = iter2.begin();
            auto end = iter2.end();
            EXPECT_NEQ(current, end);

            // The first and only incorrect assertion is the 6th
            for (uint8_t i = 0; i < 5 && current != end; i++, current++) {
                EXPECT((*current).passed());
            }
            ASSERT_NEQ(current, end);

            EXPECT_EQ(&*current, getResult().getFirstFailure());
            EXPECT_EQ(&*current, getResult().getFinalFailure());
            EXPECT(!(*current).passed());

            current++;
            bool allPassed = true;
            for (uint8_t i = 0; i < 22-6 && current != end; i++, current++) {
                if (!(*current).passed()) { allPassed = false; break; }
            }
            bool atEnd = (current == end);
            EXPECT(atEnd);
            EXPECT(allPassed);
        }

        // Test that result still indicates failure
        EXPECT(!getResult());
        EXPECT(!getResult().succeeded());
        EXPECT_NEQ(getResult().getFirstFailure(), nullptr);
        EXPECT_NEQ(getResult().getFinalFailure(), nullptr);
        EXPECT_EQ(getResult().getFirstFailure(), getResult().getFinalFailure());

        // Add an additional failure
        EXPECT_EQ(1, 2);
        ASSERT_NEQ(getResult().getFinalFailure(), nullptr);
        const Assertion* fail2 = getResult().getFinalFailure();

        // Test that result still indicates failure
        EXPECT(!getResult());
        EXPECT(!getResult().succeeded());
        EXPECT_NEQ(getResult().getFirstFailure(), nullptr);
        EXPECT_NEQ(getResult().getFinalFailure(), nullptr);
        EXPECT_NEQ(getResult().getFirstFailure(), getResult().getFinalFailure());

        // Test copying result object
        TestResult result1{getResult()};
        EXPECT_EQ(result1.succeeded(), getResult().succeeded());
        EXPECT_EQ(result1.getFirstFailure(), getResult().getFirstFailure());
        EXPECT_EQ(result1.getFinalFailure(), getResult().getFinalFailure());
        EXPECT_EQ(result1.getAssertions().begin(), getResult().getAssertions().begin());
        EXPECT_EQ(result1.getAssertions().end(), getResult().getAssertions().end());

        TestResult result2{};
        result2 = getResult();
        EXPECT_EQ(result2.succeeded(), getResult().succeeded());
        EXPECT_EQ(result2.getFirstFailure(), getResult().getFirstFailure());
        EXPECT_EQ(result2.getFinalFailure(), getResult().getFinalFailure());
        EXPECT_EQ(result2.getAssertions().begin(), getResult().getAssertions().begin());
        EXPECT_EQ(result2.getAssertions().end(), getResult().getAssertions().end());

        // Test move constructor
        TestResult emptyResult{};
        TestResult result3{reinterpret_cast<TestResult&&>(result1)};

        // Original result must now be reset
        EXPECT_EQ(result1.succeeded(), emptyResult.succeeded());
        EXPECT_EQ(result1.getFirstFailure(), emptyResult.getFirstFailure());
        EXPECT_EQ(result1.getFinalFailure(), emptyResult.getFinalFailure());
        EXPECT_EQ(result1.getAssertions().begin(), emptyResult.getAssertions().begin());
        EXPECT_EQ(result1.getAssertions().end(), emptyResult.getAssertions().end());

        EXPECT_EQ(result3.succeeded(), result2.succeeded());
        EXPECT_EQ(result3.getFirstFailure(), result2.getFirstFailure());
        EXPECT_EQ(result3.getFinalFailure(), result2.getFinalFailure());
        EXPECT_EQ(result3.getAssertions().begin(), result2.getAssertions().begin());
        EXPECT_EQ(result3.getAssertions().end(), result2.getAssertions().end());

        // Test move assignment
        TestResult result4{};
        result4 = reinterpret_cast<TestResult&&>(result2);

        // Original result must now be reset
        EXPECT_EQ(result2.succeeded(), emptyResult.succeeded());
        EXPECT_EQ(result2.getFirstFailure(), emptyResult.getFirstFailure());
        EXPECT_EQ(result2.getFinalFailure(), emptyResult.getFinalFailure());
        EXPECT_EQ(result2.getAssertions().begin(), emptyResult.getAssertions().begin());
        EXPECT_EQ(result2.getAssertions().end(), emptyResult.getAssertions().end());

        EXPECT_EQ(result4.succeeded(), result3.succeeded());
        EXPECT_EQ(result4.getFirstFailure(), result3.getFirstFailure());
        EXPECT_EQ(result4.getFinalFailure(), result3.getFinalFailure());
        EXPECT_EQ(result4.getAssertions().begin(), result3.getAssertions().begin());
        EXPECT_EQ(result4.getAssertions().end(), result3.getAssertions().end());

        // Create array of tests expected to fail. Terminate with nullptr.
        static const Assertion* fails[] = { fail1, fail2, nullptr };
        static Metadata<TestExpect> _1(*this, "expect", TestExpect::SomeFail);
        static Metadata<const Assertion**> _2(*this, "fails", static_cast<const Assertion**>(fails));
    }
Exemple #6
0
EdgeWeight two_way_fm::perform_refinement(PartitionConfig & cfg, 
                                          graph_access& G, 
                                          complete_boundary & boundary,
                                          std::vector<NodeID> & lhs_start_nodes, 
                                          std::vector<NodeID> & rhs_start_nodes, 
                                          boundary_pair * pair,        
                                          NodeWeight & lhs_part_weight,
                                          NodeWeight & rhs_part_weight,
                                          EdgeWeight & cut,
                                          bool & something_changed) {

        PartitionConfig config = cfg;//copy it since we make changes on that 
        if(lhs_start_nodes.size() == 0 or rhs_start_nodes.size() == 0) return 0; // nothing to refine

        quality_metrics qm;
        ASSERT_NEQ(pair->lhs, pair->rhs);
        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs));
        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));

        refinement_pq* lhs_queue = NULL;
        refinement_pq* rhs_queue = NULL;
        if(config.use_bucket_queues) {
                EdgeWeight max_degree = G.getMaxDegree();
                lhs_queue = new bucket_pq(max_degree); 
                rhs_queue = new bucket_pq(max_degree); 
        } else {
                lhs_queue = new maxNodeHeap(); 
                rhs_queue = new maxNodeHeap(); 
        }

        init_queue_with_boundary(config, G, lhs_start_nodes, lhs_queue, pair->lhs, pair->rhs);  
        init_queue_with_boundary(config, G, rhs_start_nodes, rhs_queue, pair->rhs, pair->lhs);  

        queue_selection_strategy* topgain_queue_select = new queue_selection_topgain(config);
        queue_selection_strategy* diffusion_queue_select = new queue_selection_diffusion(config);
        queue_selection_strategy* diffusion_queue_select_block_target = new queue_selection_diffusion_block_targets(config);
        
        vertex_moved_hashtable moved_idx; 

        std::vector<NodeID> transpositions;

        EdgeWeight inital_cut   = cut;
        int max_number_of_swaps = (int)(boundary.getBlockNoNodes(pair->lhs) + boundary.getBlockNoNodes(pair->rhs));
        int step_limit          = (int)((config.fm_search_limit/100.0)*max_number_of_swaps);
        step_limit              = std::max(step_limit, 15);
        int min_cut_index       = -1;

        refinement_pq* from_queue       = 0;
        refinement_pq* to_queue         = 0;

        PartitionID from                = 0; 
        PartitionID to                  = 0;

        NodeWeight * from_part_weight   = 0;
        NodeWeight * to_part_weight     = 0;

        stop_rule* st_rule                      = new easy_stop_rule();
        partition_accept_rule* accept_partition = NULL;
        if(config.initial_bipartitioning) {
                accept_partition = new ip_partition_accept_rule(config, cut,lhs_part_weight, rhs_part_weight, pair->lhs, pair->rhs);
        } else {
                accept_partition = new normal_partition_accept_rule(config, cut,lhs_part_weight, rhs_part_weight);
        }
        queue_selection_strategy* q_select;

        if(config.softrebalance || config.rebalance || config.initial_bipartitioning) { 
                if(config.initial_bipartitioning) {
                        q_select = diffusion_queue_select_block_target;
                } else {
                        q_select = diffusion_queue_select;
                }
        } else {
                q_select = topgain_queue_select;
        }

        //roll forwards
        EdgeWeight best_cut = cut; 
        int number_of_swaps = 0;
        for(number_of_swaps = 0; number_of_swaps < max_number_of_swaps; number_of_swaps++) {
                if(st_rule->search_should_stop(min_cut_index, number_of_swaps, step_limit)) break;

                if(lhs_queue->empty() && rhs_queue->empty()) { 
                        break; 
                }

                q_select->selectQueue(lhs_part_weight, rhs_part_weight, 
                                pair->lhs, pair->rhs,
                                from,to, 
                                lhs_queue, rhs_queue,
                                &from_queue, &to_queue);

                if(!from_queue->empty()) {
                        Gain gain = from_queue->maxValue();
                        NodeID node = from_queue->deleteMax();

                        ASSERT_TRUE(moved_idx[node].index == NOT_MOVED);

                        boundary.setBlockNoNodes(from, boundary.getBlockNoNodes(from)-1);
                        boundary.setBlockNoNodes(to, boundary.getBlockNoNodes(to)+1);

                        if(from == pair->lhs) {
                                from_part_weight = &lhs_part_weight;         
                                to_part_weight   = &rhs_part_weight;         
                        } else {
                                from_part_weight = &rhs_part_weight;         
                                to_part_weight   = &lhs_part_weight; 
                        }

                        move_node(config, G, node, moved_idx, 
                                        from_queue, to_queue, 
                                        from, to,
                                        pair,
                                        from_part_weight, to_part_weight,
                                        boundary);

                        cut -= gain;

                        if( accept_partition->accept_partition(config, cut, lhs_part_weight, rhs_part_weight, pair->lhs, pair->rhs, config.rebalance)) {
                                ASSERT_TRUE( cut <= best_cut || config.rebalance);
                                if( cut < best_cut ) {
                                        something_changed = true;
                                }
                                best_cut = cut;
                                min_cut_index = number_of_swaps;
                        }

                        transpositions.push_back(node);
                        moved_idx[node].index = MOVED;
                } else {
                        break;
                }

        }

        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs)); 
        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));
        
        //roll backwards
        for(number_of_swaps--; number_of_swaps > min_cut_index; number_of_swaps--) {
                ASSERT_TRUE(transpositions.size() > 0);

                NodeID node = transpositions.back();
                transpositions.pop_back();

                PartitionID nodes_partition = G.getPartitionIndex(node);

                if(nodes_partition == pair->lhs) {
                        from_queue       = lhs_queue;
                        to_queue         = rhs_queue;
                        from             = pair->lhs;
                        to               = pair->rhs;
                        from_part_weight = &lhs_part_weight;
                        to_part_weight   = &rhs_part_weight;
                } else {
                        from_queue       = rhs_queue;
                        to_queue         = lhs_queue;
                        from             = pair->rhs;
                        to               = pair->lhs;
                        from_part_weight = &rhs_part_weight;
                        to_part_weight   = &lhs_part_weight;

                }

                boundary.setBlockNoNodes(from, boundary.getBlockNoNodes(from)-1);
                boundary.setBlockNoNodes(to, boundary.getBlockNoNodes(to)+1);

                move_node_back(config, G, node, moved_idx, 
                                from_queue, to_queue, 
                                from, to,
                                pair,
                                from_part_weight, 
                                to_part_weight,
                                boundary);
        }

        //clean up
        cut = best_cut;

        boundary.setEdgeCut(pair, best_cut);
        boundary.setBlockWeight(pair->lhs, lhs_part_weight);
        boundary.setBlockWeight(pair->rhs, rhs_part_weight);

        delete lhs_queue;
        delete rhs_queue;
        delete topgain_queue_select;
        delete diffusion_queue_select;
        delete diffusion_queue_select_block_target;
        delete st_rule;
        delete accept_partition;

        ASSERT_EQ( cut, qm.edge_cut(G, pair->lhs, pair->rhs));
        ASSERT_TRUE(assert_directed_boundary_condition(G, boundary, pair->lhs, pair->rhs)); 
        ASSERT_TRUE(  (int)inital_cut-(int)best_cut >= 0 || cfg.rebalance); 
        // the computed partition shouldnt have a edge cut which is worse than the initial one
        return inital_cut-best_cut;
}
Exemple #7
0
void two_way_fm::move_node_back(const PartitionConfig & config, 
                                graph_access & G,
                                const NodeID & node,
                                vertex_moved_hashtable & moved_idx,
                                refinement_pq * from_queue,
                                refinement_pq * to_queue,
                                PartitionID from, 
                                PartitionID to,
                                boundary_pair * pair,         
                                NodeWeight * from_part_weight,
                                NodeWeight * to_part_weight,
                                complete_boundary & boundary) {

        ASSERT_NEQ(from, to);
        ASSERT_EQ(from, G.getPartitionIndex(node));

        //move node
        G.setPartitionIndex(node, to);         
        boundary.deleteNode(node, from, pair);

        EdgeWeight int_degree_node = 0;
        EdgeWeight ext_degree_node = 0;
        bool update_difficult = int_ext_degree(G, node, to, from, int_degree_node, ext_degree_node);

        if(ext_degree_node > 0) {
                boundary.insert(node, to, pair);
        }

        if(update_difficult) {
                boundary.postMovedBoundaryNodeUpdates(node, pair, true, false);
        }

        NodeWeight this_nodes_weight = G.getNodeWeight(node);
        (*from_part_weight) -= this_nodes_weight; 
        (*to_part_weight)   += this_nodes_weight; 

        //update neighbors
        forall_out_edges(G, e, node) {
                NodeID target = G.getEdgeTarget(e);
                PartitionID targets_partition = G.getPartitionIndex(target);

                if((targets_partition != from && targets_partition != to)) {
                        //at most difficult update nec.
                        continue; //they dont need to be updated during this refinement
                }

                EdgeWeight int_degree = 0;
                EdgeWeight ext_degree = 0;

                PartitionID other_partition = targets_partition == from ? to : from;
                int_ext_degree(G, target, targets_partition, other_partition, int_degree, ext_degree); 

                if(boundary.contains(target, targets_partition, pair)) {
                        if(ext_degree == 0) {
                                boundary.deleteNode(target, targets_partition, pair);
                        } 
                } else {
                        if(ext_degree > 0) {
                                boundary.insert(target, targets_partition, pair);
                        }
                }

        } endfor
Exemple #8
0
TEST(test_mymodule, test_function_mymodule_init_invalid_parameter)
{
    mymodule_init(-1);
    ASSERT_NEQ(mymodule_state(), (int)-1);
}