예제 #1
0
    def test_success(self):
        # set up
        class WindowDevice(AbstractDevice):
            @Solution('thermometer.too_high')
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 100

        class FanDevice(AbstractDevice):
            @Solution('thermometer.too_high')
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 50

        # test
        solutions = [
            WindowDevice().open_for_cooling,
            FanDevice().open_for_cooling
        ]
        with self.mysql.dao.SessionContext():
            best = worker._find_best_solution(solutions)
        self.assertEqual('window.open_for_cooling', best.full_name())
예제 #2
0
    def test_success(self):
        # set up
        class WindowDevice(AbstractDevice):
            @Solution("thermometer.too_high")
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 100

        class FanDevice(AbstractDevice):
            @Solution("thermometer.too_high")
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 50

        # test
        solutions = [WindowDevice().open_for_cooling, FanDevice().open_for_cooling]
        with self.mysql.dao.SessionContext():
            best = worker._find_best_solution(solutions)
        self.assertEqual("window.open_for_cooling", best.full_name())
예제 #3
0
    def test_no_fit(self):
        # set up
        class WindowDevice(AbstractDevice):
            @Solution('thermometer.too_high')
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 0

        # test
        solutions = [WindowDevice().open_for_cooling]
        with self.mysql.dao.SessionContext():
            best = worker._find_best_solution(solutions)
        self.assertIsNone(best)
예제 #4
0
    def test_no_fit(self):
        # set up
        class WindowDevice(AbstractDevice):
            @Solution("thermometer.too_high")
            def open_for_cooling(self):
                pass

            @open_for_cooling.evaluator
            def check_open(self):
                return 0

        # test
        solutions = [WindowDevice().open_for_cooling]
        with self.mysql.dao.SessionContext():
            best = worker._find_best_solution(solutions)
        self.assertIsNone(best)