Esempio n. 1
0
    def test_group_objects(self):
        """
        Test going from basic information to group objects
        """
        groups = group_objects(self.days, num_groups=3, size_of_groups=3)
        nose.tools.assert_equal(len(groups), 12)
        for d in self.days:
            groups_that_day = [g for g in groups if g.day == d]
            nose.tools.assert_equal(len(groups_that_day), 3)
        for g in groups:
            nose.tools.assert_equal(g.people, [])
            nose.tools.assert_equal(g.capacity, 3)
            nose.tools.assert_true(hasattr(g,'name')) 

        days_out = days_from_groups(groups)
        nose.tools.assert_equal(set(self.days), set(days_out))
Esempio n. 2
0
    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()