Exemplo n.º 1
0
class CostFuncTestCase(unittest.TestCase):
    def setUp(self):
        # Create a fixture of people who have already placed in groups
        # for use in testing cost functions.
        # The metrics on this group are:
        # 
        # Number of times grouped together
        # Twice: 2, Once: 2
        #
        # Number of times in same spot
        # Twice: 4, Once: 4
        # 
        # All groups are the appropriate size 
        # (N = 4, # per group = 2)
        days = ['day0', 'day1', 'day2']
        self.p1 = Person("Person 1", 1, days)
        self.p1.day0 = 'group 1'
        self.p1.day1 = 'group 0'
        self.p1.day2 = 'group 0'
        self.p2 = Person("Person 2", 2, days)
        self.p2.day0 = 'group 1'
        self.p2.day1 = 'group 0'
        self.p2.day2 = 'group 1'
        self.p3 = Person("Person 3", 3, days)
        self.p3.day0 = 'group 0'
        self.p3.day1 = 'group 1'
        self.p3.day2 = 'group 1'
        self.p4 = Person("Person 4", 4, days)
        self.p4.day0 = 'group 0'
        self.p4.day1 = 'group 1'
        self.p4.day2 = 'group 0'
        self.people = [self.p1, self.p2, self.p3, self.p4]

        num_groups = 2
        size_of_groups = 2

        self.groups = group_objects(days, num_groups, size_of_groups)
        # manually create a solution object
        for g in self.groups:
            for p in self.people:
                if getattr(p, g.day) == g.name:
                    g.people.append(p)
        self.solution = Solution(self.groups)
        self.solution.update_solution_metrics()
    
    def test_cf_overlaps(self):
        expected_freqs2 = Counter({ 2: 2, 1: 2})
        expected_freqs3 = Counter()
        nose.tools.assert_equal(self.solution.overlaps2_freqs, expected_freqs2)
        nose.tools.assert_equal(self.solution.overlaps3_freqs, expected_freqs3)
    
    def test_cf_same_spot(self):
        expected_same_spot = Counter({ 2:4, 1:4})
        nose.tools.assert_equal(self.solution.same_spot_freqs, expected_same_spot)