fix for tests and previous commit regarding estimations

tests needed updated None replaced with -1
This commit is contained in:
MirceaDan committed 2018-12-01 22:26:30 -08:00
1 parent 94ce6f1dd1
commit d3334b29d9
2 files changed
+8 -11

No files matched your search

+5 -8
View File
@@ -189,10 +189,10 @@ class TimeEstimationHelper(object):
self._totals = collections.deque([], self._rolling_window)
self._sum_total = 0
self._count = 0
self._stable_counter = None
self._stable_counter = -1
def is_stable(self):
return self._stable_counter is not None and self._stable_counter >= self._countdown
return self._stable_counter >= self._countdown
def update(self, new_estimate):
old_average_total = self.average_total
@@ -205,12 +205,9 @@ class TimeEstimationHelper(object):
self._distances.append(abs(self.average_total - old_average_total))
if -1.0 * self._threshold < self.average_distance < self._threshold:
if self._stable_counter is None:
self._stable_counter = 0
else:
self._stable_counter += 1
self._stable_counter += 1
else:
self._stable_counter = None
self._stable_counter = -1
if self.is_stable():
return self.average_total_rolling
@@ -220,7 +217,7 @@ class TimeEstimationHelper(object):
@property
def average_total(self):
if not self._count:
return -1
return 0
else:
return self._sum_total / self._count
+3 -3
View File
@@ -35,8 +35,8 @@ class EstimationTestCase(unittest.TestCase):
self.assertEqual(self.estimation_helper.average_total, expected)
@data(
((1.0, 2.0), None), # not enough values, have 1, need 3
((1.0, 2.0, 3.0), None), # not enough values, have 2, need 3
((1.0, 2.0), -1), # not enough values, have 1, need 3
((1.0, 2.0, 3.0), -1), # not enough values, have 2, need 3
((1.0, 2.0, 3.0, 4.0), 0.5), # average totals: 1.0, 1.5, 2.0, 2.5 => (3 * 0.5 / 3 = 0.5
((1.0, 2.0, 3.0, 4.0, 5.0), 0.5), # average totals: 1.0, 1.5, 2.0, 2.5, 3.0 => (0.5 + 0.5 + 0.5) / 3 = 0.5
((1.0, 2.0, 0.0, 1.0, 2.0), 0.7 / 3) # average totals: 1.0, 1.5, 1.0, 1.0, 1.2 => (0.5 + 0.0 + 0.2) / 3 = 0.7 / 3
@@ -49,7 +49,7 @@ class EstimationTestCase(unittest.TestCase):
self.assertEqual(self.estimation_helper.average_distance, expected)
@data(
((1.0, 1.0), None),
((1.0, 1.0), -1),
((1.0, 1.0, 1.0), 1.0),
((1.0, 2.0, 3.0, 4.0, 5.0), 4.0),
)