hamster-applet r769 - in trunk: hamster tests
- From: tbaugis svn gnome org
- To: svn-commits-list gnome org
- Subject: hamster-applet r769 - in trunk: hamster tests
- Date: Sat, 21 Feb 2009 13:18:41 +0000 (UTC)
Author: tbaugis
Date: Sat Feb 21 13:18:40 2009
New Revision: 769
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=769&view=rev
Log:
going for a walk and before that in fear to loos anything,
adding some non-functional code
Modified:
trunk/hamster/charting.py
trunk/tests/charting_test.py
Modified: trunk/hamster/charting.py
==============================================================================
--- trunk/hamster/charting.py (original)
+++ trunk/hamster/charting.py Sat Feb 21 13:18:40 2009
@@ -79,6 +79,28 @@
r,g,b = color.red / 65536.0, color.green / 65536.0, color.blue / 65536.0
context.set_source_rgb(r, g, b)
+class Integrator(object):
+ """an iterator, inspired by "visualizing data" book to simplify animation"""
+ def __init__(self, start_value, precision = 0):
+ """precision determines, until which decimal number we go"""
+ self.value = start_value
+ self.target_value = start_value
+ self.precision = precision
+
+ def target(self, value):
+ """target next value"""
+ self.target_value = value
+
+ def update(self):
+ """goes from current to target value
+ if there is any action needed. returns false when done"""
+ self.value += (self.target_value - self.value) / 10.0
+
+ return round(self.value, self.precision) != round(self.target_value,
+ self.precision)
+
+
+
class Chart(gtk.DrawingArea):
"""Chart constructor. Optional arguments:
orient_vertical = [True|False] - Chart orientation.
Modified: trunk/tests/charting_test.py
==============================================================================
--- trunk/tests/charting_test.py (original)
+++ trunk/tests/charting_test.py Sat Feb 21 13:18:40 2009
@@ -6,12 +6,28 @@
from hamster import charting
class TestIteratorFunctions(unittest.TestCase):
- def testOneStep(self):
- integrator = charting.Integrator(0)
+ def test_target_bigger(self):
+ integrator = charting.Integrator(0, 0)
integrator.target(10)
-
integrator.update()
- assert integrator.value == 9
+ assert integrator.value == 1
+
+ def test_target_lesser(self):
+ integrator = charting.Integrator(0, 0)
+ integrator.target(-10)
+ integrator.update()
+ assert integrator.value == -1
+
+ def test_reaches_target(self):
+ integrator = charting.Integrator(0, 0)
+ integrator.target(10)
+
+ while integrator.update():
+ print integrator.value
+
+ print round(integrator.value, 0)
+ assert round(integrator.value, 0) == 10
+
if __name__ == '__main__':
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]