[gnome-calculator] GCalc: fix parameters printing its current value



commit ec86626508db06204bddf2721252734c7ad6a835
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Oct 31 12:52:15 2019 -0600

    GCalc: fix parameters printing its current value

 gcalc/gcalc-parameter.vala | 20 +++-----------------
 tests/gcalc-parsing.vala   |  9 +++++++++
 2 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/gcalc/gcalc-parameter.vala b/gcalc/gcalc-parameter.vala
index 7022a7d4..6434d208 100644
--- a/gcalc/gcalc-parameter.vala
+++ b/gcalc/gcalc-parameter.vala
@@ -48,23 +48,9 @@ public class GCalc.Parameter : GCalc.Variable, MathParameter {
   }
   // Expression
   internal override string to_string () {
-    string str = name;
-    if (@value is MathConstantNumber) {
-      var c = @value as MathConstantNumber;
-      str = "%g".printf (c.@value ());
-    } else if (@value is MathConstantComplex) {
-      var c = @value as MathConstantComplex;
-      str = "%g".printf (c.real ());
-      double i = c.imag ();
-      if (i != 0) {
-        if (i > 0) {
-          str += "+";
-        } else {
-          str += "-";
-        }
-        str += "%gi".printf (c.imag ());
-      }
+    if (@value == null) {
+      return "0";
     }
-    return str;
+    return @value.to_string ();
   }
 }
diff --git a/tests/gcalc-parsing.vala b/tests/gcalc-parsing.vala
index d3e80721..ec88e908 100644
--- a/tests/gcalc-parsing.vala
+++ b/tests/gcalc-parsing.vala
@@ -1109,6 +1109,15 @@ class Tests {
         assert (t2 != null);
         var v2 = t2.expressions.get_item (0) as MathVariable;
         assert (v2 != null);
+        message (eq.to_string ());
+        assert (eq.to_string () == "x=0");
+        p.set_value (10.0);
+        message (eq.to_string ());
+        assert (eq.to_string () == "x=10");
+        var cx = new Constant.complex (-5.0, -10.0);
+        p.set_value (cx);
+        message (eq.to_string ());
+        assert (eq.to_string () == "x=-5-i10");
       } catch (GLib.Error error) {
         warning ("Error: %s", error.message);
       }


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