[gnome-calculator/60-split-out-a-backend-library] gcalc: adding tests for multi-level parenthesis



commit 3bf501d4bebfb38fa87eb08a60b898193348ae00
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Fri Jan 4 14:15:11 2019 -0600

    gcalc: adding tests for multi-level parenthesis

 tests/gcalc-parsing.vala       |  6 +++++
 tests/gcalc-solving-basic.vala | 57 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
---
diff --git a/tests/gcalc-parsing.vala b/tests/gcalc-parsing.vala
index fbfb8220..1e83e42a 100644
--- a/tests/gcalc-parsing.vala
+++ b/tests/gcalc-parsing.vala
@@ -562,6 +562,12 @@ class Tests {
       } catch (GLib.Error error) {
         message ("Correctly catched grouping error: %s", error.message);
       }
+      var eqman4 = new GMathEquationManager ();
+      try {
+        parser.parse ("(((1))))", eqman4);
+      } catch (GLib.Error error) {
+        message ("Correctly catched grouping error: %s", error.message);
+      }
     });
     Test.add_func ("/gcalc/parser/term/parenthesis/grouping",
     ()=>{
diff --git a/tests/gcalc-solving-basic.vala b/tests/gcalc-solving-basic.vala
index 9a1a979f..a3603861 100644
--- a/tests/gcalc-solving-basic.vala
+++ b/tests/gcalc-solving-basic.vala
@@ -268,6 +268,63 @@ class Tests {
         warning ("Error: %s", e.message);
       }
     });
+    Test.add_func ("/gcalc/solve/group/multiple-levels/1",
+    ()=>{
+      try {
+        var parser = new Parser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("(((1)))", eqman);
+        assert (eqman.equations.get_n_items () == 1);
+        var eq = eqman.equations.get_item (0) as MathEquation;
+        assert (eq != null);
+        var e = eq.expressions.get_item (0) as Polynomial;
+        assert (e != null);
+        var res = e.evaluate () as Constant;
+        assert (res != null);
+        message ("Constant Result: %s", res.to_string ());
+        assert (res.real () == 1.0);
+      } catch (GLib.Error e) {
+        warning ("Error: %s", e.message);
+      }
+    });
+    Test.add_func ("/gcalc/solve/group/multiple-levels/multiply",
+    ()=>{
+      try {
+        var parser = new Parser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("(((1)))*((((5))))", eqman);
+        assert (eqman.equations.get_n_items () == 1);
+        var eq = eqman.equations.get_item (0) as MathEquation;
+        assert (eq != null);
+        var e = eq.expressions.get_item (0) as Polynomial;
+        assert (e != null);
+        var res = e.evaluate () as Constant;
+        assert (res != null);
+        message ("Constant Result: %s", res.to_string ());
+        assert (res.real () == 5.0);
+      } catch (GLib.Error e) {
+        warning ("Error: %s", e.message);
+      }
+    });
+    Test.add_func ("/gcalc/solve/group/multiple-levels/add",
+    ()=>{
+      try {
+        var parser = new Parser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("(((1)))+((((5))))", eqman);
+        assert (eqman.equations.get_n_items () == 1);
+        var eq = eqman.equations.get_item (0) as MathEquation;
+        assert (eq != null);
+        var e = eq.expressions.get_item (0) as Polynomial;
+        assert (e != null);
+        var res = e.evaluate () as Constant;
+        assert (res != null);
+        message ("Constant Result: %s", res.to_string ());
+        assert (res.real () == 6.0);
+      } catch (GLib.Error e) {
+        warning ("Error: %s", e.message);
+      }
+    });
     Test.add_func ("/gcalc/solve/group/constant/basic-polynomial",
     ()=>{
       try {


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