2014-12-12 22:38:57 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
|
|
__author__ = "Gina Häußge <osd@foosel.net>"
|
|
|
|
|
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
|
|
|
|
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
from ddt import ddt, data, unpack
|
|
|
|
|
|
|
|
|
|
import octoprint.printer
|
|
|
|
|
|
|
|
|
|
@ddt
|
|
|
|
|
class EstimationTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2014-12-16 12:27:31 +00:00
|
|
|
self.estimation_helper = type(octoprint.printer.TimeEstimationHelper)(octoprint.printer.TimeEstimationHelper.__name__, (octoprint.printer.TimeEstimationHelper,), {
|
2014-12-17 16:31:30 +00:00
|
|
|
'STABLE_THRESHOLD': 0.1,
|
2014-12-16 12:27:31 +00:00
|
|
|
'STABLE_ROLLING_WINDOW': 3,
|
|
|
|
|
'STABLE_COUNTDOWN': 1
|
|
|
|
|
})()
|
2014-12-12 22:38:57 +00:00
|
|
|
|
|
|
|
|
@data(
|
|
|
|
|
((1.0, 2.0, 3.0, 4.0, 5.0), 3.0),
|
|
|
|
|
((1.0, 2.0, 0.0, 1.0, 2.0), 1.2),
|
|
|
|
|
((1.0, -2.0, -1.0, -2.0, 3.0), -0.2)
|
|
|
|
|
)
|
|
|
|
|
@unpack
|
|
|
|
|
def test_average_total(self, estimates, expected):
|
|
|
|
|
for estimate in estimates:
|
|
|
|
|
self.estimation_helper.update(estimate)
|
|
|
|
|
|
|
|
|
|
self.assertEquals(self.estimation_helper.average_total, expected)
|
|
|
|
|
|
|
|
|
|
@data(
|
2014-12-18 11:01:01 +00:00
|
|
|
((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, 3.0, 4.0), 0.5), # average totals: 1.0, 1.5, 2.0, 2.5 => (3 * 0.5 / 3 = 0.5
|
2014-12-16 12:27:31 +00:00
|
|
|
((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
|
2014-12-12 22:38:57 +00:00
|
|
|
)
|
|
|
|
|
@unpack
|
|
|
|
|
def test_average_distance(self, estimates, expected):
|
|
|
|
|
for estimate in estimates:
|
|
|
|
|
self.estimation_helper.update(estimate)
|
|
|
|
|
|
|
|
|
|
self.assertEquals(self.estimation_helper.average_distance, expected)
|
|
|
|
|
|
2014-12-18 11:01:01 +00:00
|
|
|
@data(
|
|
|
|
|
((1.0, 1.0), None),
|
|
|
|
|
((1.0, 1.0, 1.0), 1.0),
|
|
|
|
|
((1.0, 2.0, 3.0, 4.0, 5.0), 4.0),
|
|
|
|
|
)
|
|
|
|
|
@unpack
|
|
|
|
|
def test_average_total_rolling(self, estimates, expected):
|
|
|
|
|
for estimate in estimates:
|
|
|
|
|
self.estimation_helper.update(estimate)
|
|
|
|
|
|
|
|
|
|
self.assertEquals(self.estimation_helper.average_total_rolling, expected)
|
|
|
|
|
|
2014-12-16 12:27:31 +00:00
|
|
|
@data(
|
|
|
|
|
((1.0, 1.0, 1.0, 1.0), False), # average totals: 1.0, 1.0, 1.0, 1.0 => 3.0 / 3 = 1.0
|
|
|
|
|
((1.0, 1.0, 1.0, 1.0, 1.0), True), # average totals: 1.0, 1.0, 1.0, 1.0, 1.0 => 0.0 / 3 = 0.0
|
|
|
|
|
((1.0, 2.0, 3.0, 4.0, 5.0), False), # average totals: 1.0, 1.5, 2.0, 2.5, 3.0 => 1.5 / 3 = 0.5
|
|
|
|
|
((0.0, 0.09, 0.18, 0.27, 0.36), True) # average totals: 0.0, 0.045, 0.09, 0.135, 0.18 => (0.045 + 0.045 + 0.045) / 3 = 0.045
|
|
|
|
|
)
|
|
|
|
|
@unpack
|
|
|
|
|
def test_is_stable(self, estimates, expected):
|
|
|
|
|
for estimate in estimates:
|
|
|
|
|
self.estimation_helper.update(estimate)
|
|
|
|
|
|
|
|
|
|
self.assertEquals(self.estimation_helper.is_stable(), expected)
|
|
|
|
|
|