Repository: smok-serwis/firanka

Issue:
ModuloSeries działanie niepoprawni
Patrz test w test_series.py:TestModuloSeries:test_advanced

Comments:

Patch:
diff --git a/README.md b/README.md
index f14d95a..a660d10 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,13 @@ and will do classical linear interpolation.
 They can either utilize an existing discrete series, or be created just as
 any other discrete series would be.
 
+## Builders
+
+## DiscreteSeriesBuilder
+
+Sometimes you just need to update a DiscreteSeries, or to blang a brand new one. This little fella
+will help you out.
+
 ## Ranges
 
 Can be imported from _sai.ranges_.
diff --git a/firanka/builder.py b/firanka/builders.py
similarity index 95%
rename from firanka/builder.py
rename to firanka/builders.py
index b9d499a..7691352 100644
--- a/firanka/builder.py
+++ b/firanka/builders.py
@@ -11,10 +11,10 @@ Update knowledge of current discrete series
 """
 
 __all__ = [
-    'DiscreteKnowledgeBuilder',
+    'DiscreteSeriesBuilder',
 ]
 
-class DiscreteKnowledgeBuilder(object):
+class DiscreteSeriesBuilder(object):
     def __init__(self, series=None):
 
         if series is None:
diff --git a/firanka/series/base.py b/firanka/series/base.py
index 79572ef..2855e20 100644
--- a/firanka/series/base.py
+++ b/firanka/series/base.py
@@ -99,6 +99,10 @@ class Series(object):
 
 
 class DiscreteSeries(Series):
+    """
+    A series with lots of small rectangles interpolating something
+    """
+
     def __init__(self, data, domain=None, *args, **kwargs):
 
         data = SortedList(data)
diff --git a/firanka/series/modulo.py b/firanka/series/modulo.py
index ed72808..e0063c6 100644
--- a/firanka/series/modulo.py
+++ b/firanka/series/modulo.py
@@ -24,7 +24,12 @@ class ModuloSeries(Series):
         elif math.isinf(self.period):
             raise ValueError('Modulo series cannot have an infinite period')
 
+        # We internally translate the start of the series' domain to be at 0, because it simpler for us :D
+        self.intertrans = -self.series.domain.start
+
     def _get_for(self, item):
+        item += self.intertrans
+
         if item < 0:
             item = -(item // self.period) * self.period + item
         elif item > self.period:


Test patch:
diff --git a/tests/test_builder.py b/tests/test_builder.py
index 51c816a..9188215 100644
--- a/tests/test_builder.py
+++ b/tests/test_builder.py
@@ -3,7 +3,7 @@ from __future__ import print_function, absolute_import, division
 import six
 import unittest
 
-from firanka.builder import DiscreteKnowledgeBuilder
+from firanka.builders import DiscreteSeriesBuilder
 from firanka.series import DiscreteSeries
 
 
@@ -12,7 +12,7 @@ class TestBuilder(unittest.TestCase):
 
         ser = DiscreteSeries([(0,1), (1,2)])
 
-        kb = DiscreteKnowledgeBuilder(ser)
+        kb = DiscreteSeriesBuilder(ser)
 
         kb.put(3, 4)
         kb.put(-1, 5)
@@ -23,3 +23,15 @@ class TestBuilder(unittest.TestCase):
 
         self.assertTrue(s2.domain, '<-1;3>')
         self.assertEqual(s2.data,[(-1,6), (0,2), (1,2), (3,4)])
+
+    def test_exnihilo(self):
+        kb = DiscreteSeriesBuilder()
+
+        kb.put(0, 0)
+        kb.put(1, 1)
+
+        s = kb.as_series()
+
+        self.assertEqual(s[0],0)
+        self.assertEqual(s[1],1)
+        self.assertEqual(s.domain, '<0;1>')