Exemplo n.º 1
0
 def test_update_by_2_and_3_with_history_size_1_and_reset_get_returns_0(self):
     limited_sum = LimitedSum(1)
     limited_sum.update(2)
     limited_sum.update(3)
     limited_sum.reset()
     result = limited_sum.get()
     assert_that(result, equal_to(0))
Exemplo n.º 2
0
class SpeedLoss:
    def __init__(self, history_size):
        self.__crush = LimitedSum(history_size)
        self.__speed = LimitedSum(history_size)
        self.__history_size = history_size

    def update(self, crush, speed):
        self.__crush.update(crush)
        self.__speed.update(speed if crush else 0)

    def get(self):
        return self.__speed.get() * self.__crush.get() / self.__crush.count
Exemplo n.º 3
0
class StuckDetector:
    def __init__(self, history_size, stuck_distance, unstack_distance):
        self.__distance = LimitedSum(history_size)
        self.__stuck_distance = stuck_distance
        self.__unstack_distance = unstack_distance
        self.__previous_position = None

    def update(self, position):
        if self.__previous_position is not None:
            self.__distance.update(position.distance(self.__previous_position))
        self.__previous_position = position

    def positive_check(self):
        return (self.__distance.count == self.__distance.max_count
                and self.__distance.get() < self.__stuck_distance)

    def negative_check(self):
        return self.__distance.get() > self.__unstack_distance

    def reset(self):
        self.__distance.reset()
        self.__previous_position = None
Exemplo n.º 4
0
 def __init__(self, history_size, stuck_distance, unstack_distance):
     self.__distance = LimitedSum(history_size)
     self.__stuck_distance = stuck_distance
     self.__unstack_distance = unstack_distance
     self.__previous_position = None
Exemplo n.º 5
0
 def __init__(self, history_size):
     self.__crush = LimitedSum(history_size)
     self.__speed = LimitedSum(history_size)
     self.__history_size = history_size
Exemplo n.º 6
0
 def test_update_twice_by_1_with_history_size_1_get_returns_1(self):
     limited_sum = LimitedSum(1)
     limited_sum.update(1)
     limited_sum.update(1)
     result = limited_sum.get()
     assert_that(result, equal_to(1))
Exemplo n.º 7
0
 def test_get_empty_returns_0(self):
     limited_sum = LimitedSum(1)
     result = limited_sum.get()
     assert_that(result, equal_to(0))