From 8fe4d9b44bde3cec33314bcafe2130b6e4dac7af Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 24 Nov 2018 16:51:29 +0000
Subject: [PATCH] Dec debbuged and unit tests done.

---
 aoi_gen/tests/formatter_test.py |  141 ++++++++++++++++++++++++++++++++--------------
 aoi_gen/Variable.py             |   26 +++-----
 2 files changed, 106 insertions(+), 61 deletions(-)

diff --git a/aoi_gen/Variable.py b/aoi_gen/Variable.py
index 0777143..f27d718 100644
--- a/aoi_gen/Variable.py
+++ b/aoi_gen/Variable.py
@@ -130,18 +130,13 @@
         num=float(("{:."+str(self.precision-1)+"e}").format(num))
         places=self.fexp(num)
 
-        if(places>0):
-            decimal_places=self.precision-places-1
-            if(decimal_places<0):
-                decimal_places=0
-            format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
-        else:
-            format_str="{:."+str(self.precision)+"f}"
+        decimal_places=self.precision-places-1
+        if(decimal_places<0):
+            decimal_places=0
+        format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
 
-        return (
+        return format_str.format(num).replace(".", ",\!")
 
-                format_str.format(num).replace(".", ",\!")
-            )
 
     def getValue(self, num):
 
@@ -149,13 +144,10 @@
         num=float(("{:."+str(self.precision-1)+"e}").format(num))
         places=self.fexp(num)
 
-        if(places>0):
-            decimal_places=self.precision-places-1
-            if(decimal_places<0):
-                decimal_places=0
-            format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
-        else:
-            format_str="{:."+str(self.precision)+"f}"
+        decimal_places=self.precision-places-1
+        if(decimal_places<0):
+            decimal_places=0
+        format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
         val=format_str.format(num)
         return float(val)
 
diff --git a/aoi_gen/tests/formatter_test.py b/aoi_gen/tests/formatter_test.py
index 26fac61..73d74d2 100644
--- a/aoi_gen/tests/formatter_test.py
+++ b/aoi_gen/tests/formatter_test.py
@@ -28,32 +28,34 @@
             0,
         ]
         sci2_solutions = [
-            "1.2",
-            "1.2",
-            "3.0",
-            "3.5",
-            "5.0 \cdot 10^{-2}",
-            "-1.2",
-            "-3.0",
-            "1.1 \cdot 10^{-6}",
-            "-1.1 \cdot 10^{6}",
-            "9.8 \cdot 10^{255}",
-            "0.0",
+            "1,\!2",
+            "1,\!2",
+            "3,\!0",
+            "3,\!5",
+            "5,\!0 \cdot 10^{-2}",
+            "-1,\!2",
+            "-3,\!0",
+            "1,\!1 \cdot 10^{-6}",
+            "-1,\!1 \cdot 10^{6}",
+            "9,\!8 \cdot 10^{255}",
+            "0,\!0",
         ]
 
         sci3_solutions = [
-            "1.24",
-            "1.20",
-            "3.00",
-            "3.50",
-            "5.00 \cdot 10^{-2}",
-            "-1.23",
-            "-3.00",
-            "1.12 \cdot 10^{-6}",
-            "-1.12 \cdot 10^{6}",
-            "9.81 \cdot 10^{255}",
-            "0.00",
+            "1,\!24",
+            "1,\!20",
+            "3,\!00",
+            "3,\!50",
+            "5,\!00 \cdot 10^{-2}",
+            "-1,\!23",
+            "-3,\!00",
+            "1,\!12 \cdot 10^{-6}",
+            "-1,\!12 \cdot 10^{6}",
+            "9,\!81 \cdot 10^{255}",
+            "0,\!00",
         ]
+
+
         sci2 = Variable.FormatterFactory().get_formatter("sci 2")
         for case, result in zip(testcases, sci2_solutions):
             self.assertEqual(result, sci2.toFormat(case))
@@ -61,6 +63,57 @@
         sci3 = Variable.FormatterFactory().get_formatter("sci 3")
         for case, result in zip(testcases, sci3_solutions):
             self.assertEqual(result, sci3.toFormat(case))
+
+
+
+    def test_additionalDecTests(self):
+        testcases = [
+            1.235678910111213,
+            1.2,
+            3,
+            "3.5",
+            "0.05",
+            -1.2343567,
+            -3,
+            1.123e-6,
+            -1.123e6,
+            0,
+            32,
+        ]
+        dec2_solutions = [
+            "1,\!2",
+            "1,\!2",
+            "3,\!0",
+            "3,\!5",
+            "0,\!050",
+            "-1,\!2",
+            "-3,\!0",
+            "0,\!0000011",
+            "-1100000",
+            "0,\!0",
+            "32"
+        ]
+        dec1_solutions=[
+            "1",
+            "1",
+            "3",
+            "4",
+            "0,\!05",
+            "-1",
+            "-3",
+            "0,\!000001",
+            "-1000000",
+            "0",
+            "30",
+        ]
+
+        dec2 = Variable.FormatterFactory().get_formatter("dec 2")
+        for case, result in zip(testcases, dec2_solutions):
+            self.assertEqual(result, dec2.toFormat(case))
+
+        dec1 = Variable.FormatterFactory().get_formatter("dec 1")
+        for case, result in zip(testcases, dec1_solutions):
+            self.assertEqual(result, dec1.toFormat(case))
 
     def test_valueClass(self):
         testcases = [
@@ -77,31 +130,31 @@
             0,
         ]
         sci2_solutions = [
-            "1.2",
-            "1.2",
-            "3.0",
-            "3.5",
-            "5.0 \cdot 10^{-2}",
-            "-1.2",
-            "-3.0",
-            "1.1 \cdot 10^{-6}",
-            "-1.1 \cdot 10^{6}",
-            "9.8 \cdot 10^{255}",
-            "0.0",
+            "$1,\!2\,$",
+            "$1,\!2\,$",
+            "$3,\!0\,$",
+            "$3,\!5\,$",
+            "$5,\!0 \cdot 10^{-2}\,$",
+            "$-1,\!2\,$",
+            "$-3,\!0\,$",
+            "$1,\!1 \cdot 10^{-6}\,$",
+            "$-1,\!1 \cdot 10^{6}\,$",
+            "$9,\!8 \cdot 10^{255}\,$",
+            "$0,\!0\,$",
         ]
 
         sci3_solutions = [
-            "1.24",
-            "1.20",
-            "3.00",
-            "3.50",
-            "5.00 \cdot 10^{-2}",
-            "-1.23",
-            "-3.00",
-            "1.12 \cdot 10^{-6}",
-            "-1.12 \cdot 10^{6}",
-            "9.81 \cdot 10^{255}",
-            "0.00",
+            "$1,\!24\,$",
+            "$1,\!20\,$",
+            "$3,\!00\,$",
+            "$3,\!50\,$",
+            "$5,\!00 \cdot 10^{-2}\,$",
+            "$-1,\!23\,$",
+            "$-3,\!00\,$",
+            "$1,\!12 \cdot 10^{-6}\,$",
+            "$-1,\!12 \cdot 10^{6}\,$",
+            "$9,\!81 \cdot 10^{255}\,$",
+            "$0,\!00\,$",
         ]
 
         sci2_rounded = [

--
Gitblit v1.8.0