[gnome-calculator] Fix serializer for non-decimal base.



commit e5481ef93ffb7cdf0e030019b9f7e4496ab1ef88
Author: PioneerAxon <arth svnit gmail com>
Date:   Mon Jan 13 19:03:13 2014 +0530

    Fix serializer for non-decimal base.

 src/serializer.vala      |   24 ++++++++++++++++++++----
 src/test-serializer.vala |   14 ++++++++++++++
 2 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/src/serializer.vala b/src/serializer.vala
index 9c9eef1..dbbefc8 100644
--- a/src/serializer.vala
+++ b/src/serializer.vala
@@ -102,11 +102,27 @@ public class Serializer : Object
             int n_digits = 0;
             return cast_to_string (x, ref n_digits);
         case DisplayFormat.SCIENTIFIC:
-            int n_digits = 0;
-            return cast_to_exponential_string (x, false, ref n_digits);
+            if (representation_base == 10)
+            {
+                int n_digits = 0;
+                return cast_to_exponential_string (x, false, ref n_digits);
+            }
+            else
+            {
+                int n_digits = 0;
+                return cast_to_string (x, ref n_digits);
+            }
         case DisplayFormat.ENGINEERING:
-            int n_digits = 0;
-            return cast_to_exponential_string (x, true, ref n_digits);
+            if (representation_base == 10)
+            {
+                int n_digits = 0;
+                return cast_to_exponential_string (x, true, ref n_digits);
+            }
+            else
+            {
+                int n_digits = 0;
+                return cast_to_string (x, ref n_digits);
+            }
         }
     }
 
diff --git a/src/test-serializer.vala b/src/test-serializer.vala
index 8b059d0..fb3f83c 100644
--- a/src/test-serializer.vala
+++ b/src/test-serializer.vala
@@ -84,6 +84,13 @@ private void test_scientific (Serializer s)
     test_number (s, "1234567890", 10, 10, "1.23456789×10⁹");
     test_number (s, "0.1", 10, 10, "1×10⁻¹");
     test_number (s, "0.1234567890", 10, 10, "1.23456789×10⁻¹");
+    //Make sure other bases are represented using FIXED method.
+    test_number (s, "101010", 2, 2, "101010");
+    test_number (s, "12345670", 8, 8, "12345670");
+    test_number (s, "123456789ABCDEF0", 16, 16, "123456789ABCDEF0");
+    test_number (s, "0.010101", 2, 2, "0.010101");
+    test_number (s, "0.1234567", 8, 8, "0.1234567");
+    test_number (s, "0.123ABCDEF", 16, 16, "0.123ABCDEF");
 }
 
 private void test_engineering (Serializer s)
@@ -95,6 +102,13 @@ private void test_engineering (Serializer s)
     test_number (s, "1234567890", 10, 10, "1.23456789×10⁹");
     test_number (s, "0.1", 10, 10, "100×10⁻³");
     test_number (s, "0.1234567890", 10, 10, "123.456789×10⁻³");
+    //Make sure other bases are represented using FIXED method.
+    test_number (s, "101010", 2, 2, "101010");
+    test_number (s, "12345670", 8, 8, "12345670");
+    test_number (s, "123456789ABCDEF0", 16, 16, "123456789ABCDEF0");
+    test_number (s, "0.10101", 2, 2, "0.10101");
+    test_number (s, "0.1234567", 8, 8, "0.1234567");
+    test_number (s, "0.123ABCDEF", 16, 16, "0.123ABCDEF");
 }
 
 private void test_base_conversion (Serializer s)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]