[gnome-calculator] Expressions with base conversion



commit eea1f04e3bec90a45b71da4ad1415a406968488e
Author: PioneerAxon <arth svnit gmail com>
Date:   Fri Dec 21 02:29:51 2012 +0530

    Expressions with base conversion

 src/equation-parser.vala  |  110 ++++++++++++++++++++++++++++++++++++++++----
 src/equation.vala         |    4 +-
 src/gcalccmd.vala         |    4 +-
 src/gnome-calculator.vala |    4 +-
 src/math-equation.vala    |   29 +++++++++---
 src/serializer.vala       |   24 +++++++++-
 src/test-equation.vala    |   33 +++++++++++++-
 src/test-serializer.vala  |  102 ++++++++++++++++++++++++++---------------
 src/unit.vala             |    3 +-
 9 files changed, 248 insertions(+), 65 deletions(-)
---
diff --git a/src/equation-parser.vala b/src/equation-parser.vala
index 2410d7b..4d1f293 100644
--- a/src/equation-parser.vala
+++ b/src/equation-parser.vala
@@ -622,6 +622,32 @@ public class ConvertNode : LRNode
     }
 }
 
+public class ConvertBaseNode : ParseNode
+{
+    public ConvertBaseNode (Parser parser, LexerToken? token, uint precedence, Associativity associativity, string? value)
+    {
+        base (parser, token, precedence, associativity, value);
+    }
+
+    public override Number? solve ()
+    {
+        if (value == "hex" || value == "hexadecimal")
+            parser.set_representation_base (16);
+        else if (value == "dec" || value == "decimal")
+            parser.set_representation_base (10);
+        else if (value == "oct" || value == "octal")
+            parser.set_representation_base (8);
+        else if (value == "bin" || value == "binary")
+            parser.set_representation_base (2);
+        else
+        {
+            parser.set_error (ErrorCode.UNKNOWN_CONVERSION, token.text, token.start_index, token.end_index);
+            return null;
+        }
+        return left.solve ();
+    }
+}
+
 public class ConvertNumberNode : ParseNode
 {
     public ConvertNumberNode (Parser parser, LexerToken? token, uint precedence, Associativity associativity)
@@ -674,6 +700,7 @@ public class Parser
     private string error_token;
     private int error_token_start;
     private int error_token_end;
+    private uint representation_base;
 
     public Parser (string input, int number_base, int wordlen)
     {
@@ -683,6 +710,7 @@ public class Parser
         depth_level = 0;
         right_most = null;
         this.number_base = number_base;
+        this.representation_base = number_base;
         this.wordlen = wordlen;
         error = ErrorCode.NONE;
         error_token = null;
@@ -698,6 +726,11 @@ public class Parser
         error_token_end = input.char_count (token_end);
     }
 
+    public void set_representation_base (uint new_base)
+    {
+        representation_base = new_base;
+    }
+
     public virtual bool variable_is_defined (string name)
     {
         return false;
@@ -728,8 +761,9 @@ public class Parser
     }
 
     /* Start parsing input string. And call evaluate on success. */
-    public Number? parse (out ErrorCode error_code, out string? error_token, out uint error_start, out uint error_end)
+    public Number? parse (out uint representation_base, out ErrorCode error_code, out string? error_token, out uint error_start, out uint error_end)
     {
+        representation_base = number_base;
         /* Scan string and split into tokens */
         lexer.scan ();
 
@@ -785,6 +819,7 @@ public class Parser
             return null;
         }
 
+        representation_base = this.representation_base;
         error_code = ErrorCode.NONE;
         error_token = null;
         error_start = 0;
@@ -996,19 +1031,41 @@ public class Parser
             }
             else if (token.type == LexerTokenType.IN)
             {
-                lexer.roll_back ();
-                lexer.roll_back ();
+                if (!check_base ())
+                {
+                    lexer.roll_back ();
+                    lexer.roll_back ();
 
-                if (!unit ())
-                    return false;
-                lexer.get_next_token ();
+                    if (!unit ())
+                        return false;
+                    lexer.get_next_token ();
 
-                insert_into_tree (new ConvertNode (this, token, 0, get_associativity (token)));
+                    insert_into_tree (new ConvertNode (this, token, 0, get_associativity (token)));
 
-                if (!unit ())
-                    return false;
+                    if (!unit ())
+                        return false;
 
-                return true;
+                    return true;
+                }
+                else
+                {
+                    token = lexer.get_next_token ();
+                    if (token.type == LexerTokenType.VARIABLE)
+                    {
+                        insert_into_tree (new VariableNode (this, token_old, make_precedence_t (token_old.type), get_associativity (token_old)));
+                        insert_into_tree (new ConvertBaseNode (this, token, 0, get_associativity (token), token.text));
+                        return true;
+                    }
+                    else
+                    {
+                        lexer.roll_back ();
+                        lexer.roll_back ();
+                        lexer.roll_back ();
+                        set_error (ErrorCode.UNKNOWN_CONVERSION, token.text, token.start_index, token.end_index);
+                        return false;
+                    }
+
+                }
             }
             else if (token.type == LexerTokenType.SUP_NUMBER)
             {
@@ -1119,6 +1176,24 @@ public class Parser
                     return true;
                 }
             }
+            else if (token.type == LexerTokenType.IN)
+            {
+                token = lexer.get_next_token ();
+                if (token.type == LexerTokenType.VARIABLE)
+                {
+                    insert_into_tree (new ConstantNode (this, token_old, make_precedence_t (token_old.type), get_associativity (token)));
+                    insert_into_tree (new ConvertBaseNode (this, token, 0, get_associativity (token), token.text));
+                    return true;
+                }
+                else
+                {
+                    lexer.roll_back ();
+                    lexer.roll_back ();
+                    lexer.roll_back ();
+                    set_error (ErrorCode.UNKNOWN_CONVERSION, token.text, token.start_index, token.end_index);
+                    return false;
+                }
+            }
             else
             {
                 lexer.roll_back ();
@@ -1137,6 +1212,21 @@ public class Parser
         }
     }
 
+    private bool check_base ()
+    {
+        var token = lexer.get_next_token ();
+        foreach (string s in "hex,hexadecimal,dec,decimal,oct,octal,bin,binary".split (","))
+        {
+            if (token.text == s)
+            {
+                lexer.roll_back ();
+                return true;
+            }
+        }
+        lexer.roll_back ();
+        return false;
+    }
+
     private bool unit ()
     {
         var token = lexer.get_next_token ();
diff --git a/src/equation.vala b/src/equation.vala
index 7582894..361f047 100644
--- a/src/equation.vala
+++ b/src/equation.vala
@@ -114,12 +114,12 @@ public class Equation
         this.expression = expression;
     }
 
-    public new Number? parse (out ErrorCode error_code = null, out string error_token = null, out uint error_start = null, out uint error_end = null)
+    public new Number? parse (out uint representation_base = null, out ErrorCode error_code = null, out string error_token = null, out uint error_start = null, out uint error_end = null)
     {
         var parser = new EquationParser (this, expression);
         mp_clear_error ();
 
-        var z = parser.parse (out error_code, out error_token, out error_start, out error_end);
+        var z = parser.parse (out representation_base, out error_code, out error_token, out error_start, out error_end);
 
         /* Error during parsing */
         if (error_code != ErrorCode.NONE)
diff --git a/src/gcalccmd.vala b/src/gcalccmd.vala
index 35f37dc..38b4f74 100644
--- a/src/gcalccmd.vala
+++ b/src/gcalccmd.vala
@@ -25,8 +25,10 @@ static void solve (string equation)
     e.angle_units = AngleUnit.DEGREES;
 
     ErrorCode ret;
-    var z = e.parse (out ret, null);
+    uint representation_base;
+    var z = e.parse (out representation_base, out ret);
 
+    result_serializer.set_representation_base (representation_base);
     if (z != null)
         stdout.printf ("%s\n", result_serializer.to_string (z));
     else if (ret == ErrorCode.MP)
diff --git a/src/gnome-calculator.vala b/src/gnome-calculator.vala
index 7401ed4..e560d2f 100644
--- a/src/gnome-calculator.vala
+++ b/src/gnome-calculator.vala
@@ -357,10 +357,12 @@ public class Calculator : Gtk.Application
             e.angle_units = AngleUnit.DEGREES;
 
             ErrorCode error;
-            var result = e.parse (out error);
+            uint representation_base;
+            var result = e.parse (out representation_base, out error);
             if (result != null)
             {
                 var serializer = new Serializer (DisplayFormat.AUTOMATIC, 10, 9);
+                serializer.set_representation_base (representation_base);
                 stdout.printf ("%s\n", serializer.to_string (result));
                 return Posix.EXIT_SUCCESS;
             }
diff --git a/src/math-equation.vala b/src/math-equation.vala
index 5163909..9edb169 100644
--- a/src/math-equation.vala
+++ b/src/math-equation.vala
@@ -20,6 +20,7 @@ public enum NumberMode
 private class MathEquationState
 {
     public Number ans;             /* Previously calculated answer */
+    public uint ans_base;          /* Representation base of previous answer. */
     public string expression;      /* Expression entered by user */
     public int ans_start;          /* Start character for ans variable in expression */
     public int ans_end;            /* End character for ans variable in expression */
@@ -39,6 +40,7 @@ private class SolveData
     public string error;
     public uint error_start;
     public uint error_end;
+    public uint representation_base;
 }
 
 public class MathEquation : Gtk.TextBuffer
@@ -193,6 +195,7 @@ public class MathEquation : Gtk.TextBuffer
         queue = new AsyncQueue<SolveData> ();
 
         state.ans = new Number.integer (0);
+        state.ans_base = 10;
 
         ans_tag = create_tag (null, "weight", Pango.Weight.BOLD, null);
     }
@@ -223,7 +226,9 @@ public class MathEquation : Gtk.TextBuffer
         get_iter_at_mark (out ans_end, ans_end_mark);
 
         var orig_ans_text = get_text (ans_start, ans_end, false);
+        serializer.set_representation_base (state.ans_base);
         var ans_text = serializer.to_string (state.ans);
+        serializer.set_representation_base (serializer.get_base ());
         if (orig_ans_text != ans_text)
         {
             in_undo_operation = true;
@@ -376,6 +381,7 @@ public class MathEquation : Gtk.TextBuffer
 
         var s = new MathEquationState ();
         s.ans = state.ans;
+        s.ans_base = state.ans_base;
         s.expression = display;
         s.ans_start = ans_start;
         s.ans_end = ans_end;
@@ -427,6 +433,7 @@ public class MathEquation : Gtk.TextBuffer
         in_undo_operation = true;
 
         state.ans = s.ans;
+        state.ans_base = s.ans_base;
         set_text (s.expression, -1);
         Gtk.TextIter cursor;
         get_iter_at_offset (out cursor, s.cursor);
@@ -738,10 +745,17 @@ public class MathEquation : Gtk.TextBuffer
         clear_ans (false);
     }
 
-    public void set_number (Number x)
+    public void set_number (Number x, uint representation_base = 0)
     {
+        if (representation_base != 0)
+            serializer.set_representation_base (representation_base);
+
         /* Show the number in the user chosen format */
         var text = serializer.to_string (x);
+
+        if (representation_base != 0)
+            serializer.set_representation_base (serializer.get_base ());
+
         set_text (text, -1);
         state.ans = x;
 
@@ -824,14 +838,14 @@ public class MathEquation : Gtk.TextBuffer
         }
     }
 
-    private Number? parse (string text, out ErrorCode error_code = null, out string error_token = null, out uint error_start, out uint error_end)
+    private Number? parse (string text, out uint representation_base, out ErrorCode error_code = null, out string error_token = null, out uint error_start, out uint error_end)
     {
         var equation = new MEquation (this, text);
         equation.base = serializer.get_base ();
         equation.wordlen = word_size;
         equation.angle_units = angle_units;
 
-        return equation.parse (out error_code, out error_token, out error_start, out error_end);
+        return equation.parse (out representation_base, out error_code, out error_token, out error_start, out error_end);
     }
 
     /*
@@ -860,8 +874,9 @@ public class MathEquation : Gtk.TextBuffer
 
         ErrorCode error_code;
         string error_token;
-        uint error_start, error_end;
-        var z = parse (text, out error_code, out error_token, out error_start, out error_end);
+        uint error_start, error_end, representation_base;
+        var z = parse (text, out representation_base, out error_code, out error_token, out error_start, out error_end);
+        solvedata.representation_base = representation_base;
         switch (error_code)
         {
             case ErrorCode.NONE:
@@ -947,7 +962,7 @@ public class MathEquation : Gtk.TextBuffer
             notify_property ("error-token-end");
         }
         else if (result.number_result != null)
-            set_number (result.number_result);
+            set_number (result.number_result, result.representation_base);
         else if (result.text_result != null)
             set (result.text_result);
 
@@ -1248,4 +1263,4 @@ private class MEquation : Equation
     {
         return UnitManager.get_default ().convert_by_symbol (x, x_units, z_units);
     }
-}
\ No newline at end of file
+}
diff --git a/src/serializer.vala b/src/serializer.vala
index 49bfc46..9c9eef1 100644
--- a/src/serializer.vala
+++ b/src/serializer.vala
@@ -26,6 +26,7 @@ public class Serializer : Object
     private bool show_zeroes;        /* Set if trailing zeroes should be shown. */
 
     private int number_base;         /* Numeric base */
+    private uint representation_base;/* Representation base. */
 
     private unichar radix;           /* Locale specific radix string. */
     private unichar tsep;            /* Locale specific thousands separator. */
@@ -46,6 +47,7 @@ public class Serializer : Object
         tsep_count = 3;
 
         this.number_base = number_base;
+        this.representation_base = number_base;
         leading_digits = 12;
         this.trailing_digits = trailing_digits;
         show_zeroes = false;
@@ -55,6 +57,12 @@ public class Serializer : Object
 
     public string to_string (Number x)
     {
+        /* For base conversion equation, use FIXED format. */
+        if (representation_base != number_base)
+        {
+            int n_digits = 0;
+            return cast_to_string (x, ref n_digits);
+        }
         switch (format)
         {
         default:
@@ -118,6 +126,16 @@ public class Serializer : Object
         return number_base;
     }
 
+    public void set_representation_base (uint representation_base)
+    {
+        this.representation_base = representation_base;
+    }
+
+    public uint get_representation_base ()
+    {
+        return representation_base;
+    }
+
     public void set_radix (unichar radix)
     {
         this.radix = radix;
@@ -203,7 +221,7 @@ public class Serializer : Object
         var string = new StringBuilder.sized (1024);
 
         var x_real = x.real_component ();
-        cast_to_string_real (x_real, number_base, false, ref n_digits, string);
+        cast_to_string_real (x_real, (int) representation_base, false, ref n_digits, string);
         if (x.is_complex ())
         {
             var x_im = x.imaginary_component ();
@@ -217,7 +235,7 @@ public class Serializer : Object
 
             var s = new StringBuilder.sized (1024);
             int n_complex_digits = 0;
-            cast_to_string_real (x_im, 10, force_sign, ref n_complex_digits, s);
+            cast_to_string_real (x_im, (int) representation_base, force_sign, ref n_complex_digits, s);
             if (n_complex_digits > n_digits)
                 n_digits = n_complex_digits;
             if (s.str == "0" || s.str == "+0" || s.str == "â0")
@@ -270,7 +288,7 @@ public class Serializer : Object
         var i = 0;
         do
         {
-            if (this.number_base == 10 && show_tsep && i == tsep_count)
+            if (number_base == 10 && show_tsep && i == tsep_count)
             {
                 string.prepend_unichar (tsep);
                 i = 0;
diff --git a/src/test-equation.vala b/src/test-equation.vala
index ed1f58f..6f15ca1 100644
--- a/src/test-equation.vala
+++ b/src/test-equation.vala
@@ -33,7 +33,8 @@ private void test (string expression, string expected, ErrorCode expected_error)
     equation.angle_units = angle_units;
 
     ErrorCode error;
-    var result = equation.parse (out error, null);
+    uint representation_base;
+    var result = equation.parse (out representation_base, out error);
 
     if (result == null)
     {
@@ -56,6 +57,7 @@ private void test (string expression, string expected, ErrorCode expected_error)
     else
     {
         var serializer = new Serializer (DisplayFormat.FIXED, number_base, 9);
+        serializer.set_representation_base (representation_base);
         var result_str = serializer.to_string (result);
 
         if (expected_error != ErrorCode.NONE)
@@ -590,12 +592,41 @@ private void test_equations ()
     //test ("ÂÂ10â", "10â", 0);
 }
 
+private void test_base_conversion ()
+{
+    number_base = 10;
+    wordlen = 32;
+    angle_units = AngleUnit.DEGREES;
+    enable_conversions = true;
+    enable_variables = true;
+
+    test ("10 in bin", "1010â", 0);
+    test ("10 in oct", "12â", 0);
+    test ("10 in dec", "10", 0);
+    test ("10 in hex", "Aââ", 0);
+    test ("10 in binary", "1010â", 0);
+    test ("10 in octal", "12â", 0);
+    test ("10 in decimal", "10", 0);
+    test ("10 in hexadecimal", "Aââ", 0);
+
+    test ("1010â in dec", "10", 0);
+    test ("12â in dec", "10", 0);
+    test ("10 in dec", "10", 0);
+    test ("Aââ in dec", "10", 0);
+
+    test ("x in bin", "10â", 0);
+    test ("x in oct", "2â", 0);
+    test ("x in dec", "2", 0);
+    test ("x in hex", "2ââ", 0);
+}
+
 public int main (string args[])
 {
     Intl.setlocale (LocaleCategory.ALL, "C");
 
     test_conversions ();
     test_equations ();
+    test_base_conversion ();
 
     if (fail_count == 0)
         stdout.printf ("Passed all %i tests\n", pass_count);
diff --git a/src/test-serializer.vala b/src/test-serializer.vala
index e8c4983..8b059d0 100644
--- a/src/test-serializer.vala
+++ b/src/test-serializer.vala
@@ -25,10 +25,11 @@ private void fail (string text)
     fail_count++;
 }
 
-private void test_number (Serializer s, string number, int base_value, string expected_string)
+private void test_number (Serializer s, string number, int base_value, int representation_base, string expected_string)
 {
     var n = mp_set_from_string (number, base_value);
     s.set_base (base_value);
+    s.set_representation_base (representation_base);
     if (s.to_string (n) == expected_string)
         pass ();
     else
@@ -39,61 +40,84 @@ private void test_fixed (Serializer s)
 {
     s.set_number_format (DisplayFormat.FIXED);
 
-    test_number (s, "123456789012345678901234", 10, "123,456,789,012,345,678,901,234");
-    test_number (s, "0.1234567890123456789012", 10, "0.123456789");
-    test_number (s, "101010101010101010101010", 2, "101010101010101010101010");
-    test_number (s, "0.1010101010101010101010", 2, "0.101010101");
-    test_number (s, "123456701234567012345670", 8, "123456701234567012345670");
-    test_number (s, "0.1234567012345670123456", 8, "0.123456701");
-    test_number (s, "123456789ABCDEF012345678", 16, "123456789ABCDEF012345678");
-    test_number (s, "0.ABCDEF0123456789ABCDEF", 16, "0.ABCDEF012");
+    test_number (s, "123456789012345678901234", 10, 10, "123,456,789,012,345,678,901,234");
+    test_number (s, "0.1234567890123456789012", 10, 10, "0.123456789");
+    test_number (s, "101010101010101010101010", 2, 2, "101010101010101010101010");
+    test_number (s, "0.1010101010101010101010", 2, 2, "0.101010101");
+    test_number (s, "123456701234567012345670", 8, 8, "123456701234567012345670");
+    test_number (s, "0.1234567012345670123456", 8, 8, "0.123456701");
+    test_number (s, "123456789ABCDEF012345678", 16, 16, "123456789ABCDEF012345678");
+    test_number (s, "0.ABCDEF0123456789ABCDEF", 16, 16, "0.ABCDEF012");
 }
 
 private void test_automatic (Serializer s)
 {
     s.set_number_format (DisplayFormat.AUTOMATIC);
 
-    test_number (s, "0.10", 10, "0.1");
-    test_number (s, "0.12345678901234567890", 10, "0.123456789");
-    test_number (s, "123456789012", 10, "123,456,789,012");
-    test_number (s, "12345678901234567890", 10, "1.23456789Ã10Ââ");
-
-    test_number (s, ".10", 2, "0.1");
-    test_number (s, "0.10101010101010101010", 2, "0.101010101");
-    test_number (s, "1010101010101010101010101010101010101010101010101010101010101010", 2, "1010101010101010101010101010101010101010101010101010101010101010");
-    test_number (s, "10101010101010101010101010101010101010101010101010101010101010101", 2, "1.010101011Ã10ââ");
-
-    test_number (s, "0.10", 8, "0.1");
-    test_number (s, "0.12345670123456701234", 8, "0.123456701");
-    test_number (s, "1234567012345670123456", 8, "1234567012345670123456");
-    test_number (s, "12345670123456701234567", 8, "1.234567012Ã10ÂÂ");
-
-    test_number (s, "0.10", 16, "0.1");
-    test_number (s, "0.123456789ABCDEF01234", 16, "0.12345678A");
-    test_number (s, "123456789ABCDEF0", 16, "123456789ABCDEF0");
-    test_number (s, "123456789ABCEDF01", 16, "1.23456789BÃ10Ââ");
+    test_number (s, "0.10", 10, 10, "0.1");
+    test_number (s, "0.12345678901234567890", 10, 10, "0.123456789");
+    test_number (s, "123456789012", 10, 10, "123,456,789,012");
+    test_number (s, "12345678901234567890", 10, 10, "1.23456789Ã10Ââ");
+
+    test_number (s, ".10", 2, 2, "0.1");
+    test_number (s, "0.10101010101010101010", 2, 2, "0.101010101");
+    test_number (s, "1010101010101010101010101010101010101010101010101010101010101010", 2, 2, "1010101010101010101010101010101010101010101010101010101010101010");
+    test_number (s, "10101010101010101010101010101010101010101010101010101010101010101", 2, 2, "1.010101011Ã10ââ");
+
+    test_number (s, "0.10", 8, 8, "0.1");
+    test_number (s, "0.12345670123456701234", 8, 8, "0.123456701");
+    test_number (s, "1234567012345670123456", 8, 8, "1234567012345670123456");
+    test_number (s, "12345670123456701234567", 8, 8, "1.234567012Ã10ÂÂ");
+
+    test_number (s, "0.10", 16, 16, "0.1");
+    test_number (s, "0.123456789ABCDEF01234", 16, 16, "0.12345678A");
+    test_number (s, "123456789ABCDEF0", 16, 16, "123456789ABCDEF0");
+    test_number (s, "123456789ABCEDF01", 16, 16, "1.23456789BÃ10Ââ");
 }
 
 private void test_scientific (Serializer s)
 {
     s.set_number_format (DisplayFormat.SCIENTIFIC);
 
-    test_number (s, "1", 10, "1");
-    test_number (s, "10", 10, "1Ã10Â");
-    test_number (s, "1234567890", 10, "1.23456789Ã10â");
-    test_number (s, "0.1", 10, "1Ã10âÂ");
-    test_number (s, "0.1234567890", 10, "1.23456789Ã10âÂ");
+    test_number (s, "1", 10, 10, "1");
+    test_number (s, "10", 10, 10, "1Ã10Â");
+    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âÂ");
 }
 
 private void test_engineering (Serializer s)
 {
     s.set_number_format (DisplayFormat.ENGINEERING);
 
-    test_number (s, "1", 10, "1");
-    test_number (s, "10", 10, "10");
-    test_number (s, "1234567890", 10, "1.23456789Ã10â");
-    test_number (s, "0.1", 10, "100Ã10âÂ");
-    test_number (s, "0.1234567890", 10, "123.456789Ã10âÂ");
+    test_number (s, "1", 10, 10, "1");
+    test_number (s, "10", 10, 10, "10");
+    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âÂ");
+}
+
+private void test_base_conversion (Serializer s)
+{
+    test_number (s, "12â", 10, 2, "1010â");
+    test_number (s, "10", 10, 2, "1010â");
+    test_number (s, "Aââ", 10, 2, "1010â");
+    test_number (s, "1234567890123456789012345678901234567890", 10, 2, "1110100000110010010010000001110101110000001101101111110011101110001010110010111100010111111001011011001110001111110000101011010010â");
+
+    test_number (s, "1010â", 10, 8, "12â");
+    test_number (s, "10", 10, 8, "12â");
+    test_number (s, "Aââ", 10, 8, "12â");
+    test_number (s, "1234567890123456789012345678901234567890", 10, 8, "16406222016560155763561262742771331617605322â");
+
+    test_number (s, "1010â", 10, 10, "10");
+    test_number (s, "12â", 10, 10, "10");
+    test_number (s, "Aââ", 10, 10, "10");
+
+    test_number (s, "1010â", 10, 16, "Aââ");
+    test_number (s, "12â", 10, 16, "Aââ");
+    test_number (s, "10", 10, 16, "Aââ");
+    test_number (s, "1234567890123456789012345678901234567890", 10, 16, "3A0C92075C0DBF3B8ACBC5F96CE3F0AD2ââ");
+
 }
 
 static int main (string[] args)
@@ -110,6 +134,8 @@ static int main (string[] args)
     test_scientific (serializer);
     test_engineering (serializer);
 
+    test_base_conversion (serializer);
+
     if (fail_count == 0)
         stdout.printf ("Passed all %i tests\n", pass_count);
     else
diff --git a/src/unit.vala b/src/unit.vala
index fec4078..d11048c 100644
--- a/src/unit.vala
+++ b/src/unit.vala
@@ -296,7 +296,6 @@ public class Unit : Object
         var equation = new UnitSolveEquation (function, x);
         equation.base = 10;
         equation.wordlen = 32;
-
         var z = equation.parse ();
         if (z == null)
             warning ("Failed to convert value: %s", function);
@@ -324,4 +323,4 @@ private class UnitSolveEquation : Equation
     {
         return x;
     }
-}
\ No newline at end of file
+}



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