Пример #1
0
class Test_is_in_range_and_distance(object):
    @classmethod
    def setup_class(self):
        """
        Setup code run before any tests are run
        """
        self.alert = Alert({    'id': None,
                                'onsetDate': None,
                                'expireDate': None,
                                'isUpdate': False,
                                'isCancel': False,
                                'locations':[] 
                            })

    @classmethod
    def teardown_class(self):
        """
        Teardown code run after all tests are run
        """
        self.alert = None

    def setUp(self):
        """
        Run before each test method is run
        """
        del self.alert.locations[:]
        self.alert.add_all_locations([(00.00, 00.00), (77.77, 77.77)])
        self.alert.isCancel = False

    def test_is_in_range_happy_path(self):
        assert_true(self.alert.is_in_range((00.00, 00.00), 1.0))
        assert_false(self.alert.is_in_range((90.00, 00.00), 1.0))

    def test_is_in_range_max(self):
        assert_true(self.alert.is_in_range((00.14, 00.00), 10.0))
        assert_false(self.alert.is_in_range((00.15, 00.00), 10.0))

    def test_is_in_range_negative_num(self):
        assert_false(self.alert.is_in_range((00.00, 00.00), -10.0))

    def test_is_in_range_canceled_alert(self):
        assert_true(self.alert.is_in_range(00.00, 00.00), 1.0)
        self.alert.isCancel = True
        assert_false(self.alert.is_in_range(00.00, 00.00), 1.0)

    def test_distance_happy_path(self):
        assert_almost_equal(self.alert.distance((00.00, 00.00)), 0)
        assert_almost_equal(self.alert.distance((00.14, 00.00)), 9.675790717)