[gnome-calculator/60-split-out-a-backend-library] gcalc: adding tests for multiple equations



commit e5852682305d72ebc9ed71f6f564e7dbd83a025a
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Sun Jan 6 02:02:27 2019 -0600

    gcalc: adding tests for multiple equations

 tests/gcalc-parsing.vala       | 43 ++++++++++++++++++++++++++++++++++++++++++
 tests/gcalc-solving-basic.vala | 36 +++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)
---
diff --git a/tests/gcalc-parsing.vala b/tests/gcalc-parsing.vala
index a8cf1cda..9342d2df 100644
--- a/tests/gcalc-parsing.vala
+++ b/tests/gcalc-parsing.vala
@@ -958,6 +958,49 @@ class Tests {
         warning ("Error: %s", error.message);
       }
     });
+    Test.add_func ("/gcalc/parser/variable/equations/asigments",
+    ()=>{
+      try {
+        var parser = new GParser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("x=3", eqman);
+        parser.parse ("y=x", eqman);
+        assert (eqman.equations.get_n_items () == 2);
+        var eq = eqman.equations.get_item (0) as MathEquation;
+        assert (eq != null);
+        assert (eq.expressions.get_n_items () == 1);
+        var a = eq.expressions.get_item (0) as Assign;
+        assert (a != null);
+        assert (a.expressions.get_n_items () == 2);
+        var v = a.expressions.get_item (0) as Variable;
+        assert (v != null);
+        var e = a.expressions.get_item (1) as Polynomial;
+        assert (e != null);
+        assert (e.expressions.get_n_items () == 1);
+        var t = e.expressions.get_item (0) as Term;
+        assert (t != null);
+        var c = t.expressions.get_item (0) as Constant;
+        assert (c != null);
+        var eq2 = eqman.equations.get_item (1) as MathEquation;
+        assert (eq2 != null);
+        message (eq2.to_string ());
+        assert (eq2.expressions.get_n_items () == 1);
+        var a2 = eq2.expressions.get_item (0) as Assign;
+        assert (a2 != null);
+        assert (a2.expressions.get_n_items () == 2);
+        var v2 = a2.expressions.get_item (0) as Variable;
+        assert (v2 != null);
+        var e2 = a2.expressions.get_item (1) as Polynomial;
+        assert (e2 != null);
+        assert (e2.expressions.get_n_items () == 1);
+        var t2 = e2.expressions.get_item (0) as Term;
+        assert (t2 != null);
+        var v3 = t2.expressions.get_item (0) as Variable;
+        assert (v3 != null);
+      } catch (GLib.Error error) {
+        warning ("Error: %s", error.message);
+      }
+    });
     return Test.run ();
   }
 }
diff --git a/tests/gcalc-solving-basic.vala b/tests/gcalc-solving-basic.vala
index 86f01545..28978422 100644
--- a/tests/gcalc-solving-basic.vala
+++ b/tests/gcalc-solving-basic.vala
@@ -1141,6 +1141,42 @@ class Tests {
         warning ("Error: %s", e.message);
       }
     });
+    Test.add_func ("/gcalc/solve/equations/solve/variable/assignment",
+    ()=>{
+      try {
+        var parser = new GParser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("x=3", eqman);
+        parser.parse ("y=x", eqman);
+        assert (eqman.equations.get_n_items () == 2);
+        var eq = eqman.equations.get_item (0) as MathEquation;
+        assert (eq != null);
+        var res = eq.solve ();
+        if (res is ErrorResult) {
+          warning ("Error: %s", res.error.to_string ());
+        }
+        assert (res.expression != null);
+        assert (res.expression is Constant);
+        message ("Result: %s", res.expression.to_string ());
+        var c = res.expression as Constant;
+        assert (c != null);
+        assert (c.real () == 3.0);
+        var eq2 = eqman.equations.get_item (0) as MathEquation;
+        assert (eq2 != null);
+        var res2 = eq2.solve ();
+        if (res2 is ErrorResult) {
+          warning ("Error: %s", res2.error.to_string ());
+        }
+        assert (res2.expression != null);
+        assert (res2.expression is Constant);
+        message ("Result: %s", res2.expression.to_string ());
+        var c2 = res2.expression as Constant;
+        assert (c2 != null);
+        assert (c2.real () == 3.0);
+      } catch (GLib.Error e) {
+        warning ("Error: %s", e.message);
+      }
+    });
     return Test.run ();
   }
 }


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