Example #1
0
    def test_total_infection(self):
        print '\n TESTING TOTAL INFECTION \n'
        # generate a random graph to test on
        graph_generator = gg(self.MAX_NUM_SUBGRAPHS, self.MAX_SUBGRAPH_SIZE)

        for i in range(self.TEST_SIZE):
            G = graph_generator.random_user_graph()

            # version to infect
            version = 'v.Test' 

            # randomly pick a user to infect
            rand_uuid = rand.randint(1, len(G)-1 )

            # get component that user is in which should be infected
            expect_infected = self._get_cc_containing_uuid(G, rand_uuid) 
            actual_infected = total_infection(G, rand_uuid, version) 

            # check that version was spread properly
            assert(actual_infected == expect_infected)
            assert(self._component_totally_infected(G, actual_infected, version))
            assert(self._infection_contained(G, actual_infected, version))
            print 'PASSED TEST #', i + 1, 'OF TEST TOTAL INFECTION'
Example #2
0
    def test_limited_infection(self):
        print 'TESTING LIMITED INFECTION \n'
        graph_generator = gg(self.MAX_NUM_SUBGRAPHS, self.MAX_SUBGRAPH_SIZE)

        for i in range(self.TEST_SIZE):
            # get a random graph of somewhat connected cliques to test on
            SG = graph_generator.random_student_graph()
            version = 'v.Test' 
            num_to_infect = rand.randint(1, 100)
            delta = int(num_to_infect / 5)
            actual_infected = limited_infection(SG, num_to_infect, delta, version)

            if actual_infected is None:
                # check that there were no components with in the size range
                component_len = [len(c) for c in nx.connected_components(SG)]
                assert subset_sum_within_range(component_len, num_to_infect, delta) is None
                print 'PASSED TEST #', i + 1, 'OF TEST LIMITED INFECTION'
            else:
                # check that athe appropriate number of ppl were infected
                assert num_to_infect - delta <= len(actual_infected) <= num_to_infect + delta
                # check that version was spread properly
                assert(self._component_totally_infected(SG, actual_infected, version))
                assert(self._infection_contained(SG, actual_infected, version))
                print 'PASSED TEST #', i + 1, 'OF TEST LIMITED INFECTION'