[gnome-calculator/60-split-out-a-backend-library] gcalc: Solver now has a MathEquationManager



commit ccc24c1c085d0f180d76d8e9a331b17ca89df26c
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Thu Jan 3 11:22:47 2019 -0600

    gcalc: Solver now has a MathEquationManager

 gcalc/gcalc-gsolver.vala       | 10 +++++++---
 gcalc/gcalc-solver.vala        |  1 +
 tests/gcalc-parsing.vala       |  2 +-
 tests/gcalc-solving-basic.vala | 39 +++++++++++++++++++++++++++++++++++++++
 tests/meson.build              | 23 +++++++++++++++++------
 5 files changed, 65 insertions(+), 10 deletions(-)
---
diff --git a/gcalc/gcalc-gsolver.vala b/gcalc/gcalc-gsolver.vala
index ffaea6d2..8a90e0da 100644
--- a/gcalc/gcalc-gsolver.vala
+++ b/gcalc/gcalc-gsolver.vala
@@ -21,13 +21,17 @@
 using GCalc;
 
 public class GCalc.GSolver : Object, Solver {
+  construct {
+    equation_manager = new GMathEquationManager ();
+  }
+  // Sover
+  public MathEquationManager equation_manager { get; set; }
   public Result solve (string str) throws GLib.Error {
     var p = new Parser ();
-    var em = new GMathEquationManager ();
     Result res;
     try {
-      p.parse (str, em);
-      res = new GResult ((Expression) em.equations.get_item (0)) as Result; // FIXME: This should return a 
constant object
+      p.parse (str, equation_manager);
+      res = new GResult ((Expression) equation_manager.equations.get_item (0)) as Result; // FIXME: This 
should return a constant object
     } catch (GLib.Error e) {
       var err = new GErrorResult (e.message);
       res = new GResult.with_error ((Expression) new GExpression (), (ErrorResult) err) as Result; // FIXME: 
This should return a constant object
diff --git a/gcalc/gcalc-solver.vala b/gcalc/gcalc-solver.vala
index 68e4986d..49d7bff6 100644
--- a/gcalc/gcalc-solver.vala
+++ b/gcalc/gcalc-solver.vala
@@ -19,6 +19,7 @@
  *      Daniel Espinosa <esodan gmail com>
  */
 public interface GCalc.Solver : Object {
+  public abstract MathEquationManager equation_manager { get; set; }
   public abstract Result solve (string str) throws GLib.Error;
 }
 
diff --git a/tests/gcalc-parsing.vala b/tests/gcalc-parsing.vala
index a91c70c5..06a4fc9e 100644
--- a/tests/gcalc-parsing.vala
+++ b/tests/gcalc-parsing.vala
@@ -1,6 +1,6 @@
 /* -*- Mode: Vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
 /*
- * libvda Unit Tests
+ * GCalc Unit Tests
  * Copyright (C) Daniel Espinosa Ortiz 2018 <esodan gmail com>
  *
  * libgda is free software: you can redistribute it and/or modify it
diff --git a/tests/gcalc-solving-basic.vala b/tests/gcalc-solving-basic.vala
new file mode 100644
index 00000000..932f4e38
--- /dev/null
+++ b/tests/gcalc-solving-basic.vala
@@ -0,0 +1,39 @@
+/* -*- Mode: Vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ * GCalc Unit Tests
+ * Copyright (C) Daniel Espinosa Ortiz 2018 <esodan gmail com>
+ *
+ * libgda is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+using GCalc;
+
+class Tests {
+  static int main (string[] args)
+  {
+    GLib.Intl.setlocale (GLib.LocaleCategory.ALL, "");
+    Test.init (ref args);
+    Test.add_func ("/gcalc/parser/constant/integer",
+    ()=>{
+      try {
+        var parser = new Parser ();
+        var eqman = new GMathEquationManager ();
+        parser.parse ("1", eqman);
+
+      } catch (GLib.Error error) {
+        warning ("Error: %s", error.message);
+      }
+    });
+    return Test.run ();
+  }
+}
diff --git a/tests/meson.build b/tests/meson.build
index 00904582..eb459673 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -51,10 +51,6 @@ test_serializer = executable('test-serializer', test_serializer_sources,
 test('Serializer test', test_serializer)
 endif
 
-test_main_interfaces_sources = [
-  'gcalc-parsing.vala',
-]
-
 tests_deps = [
   gio,
   glib,
@@ -67,8 +63,23 @@ tests_deps = [
   inc_rooth_dep
 ]
 
-test_interfaces = executable('gcalc-interfaces', test_main_interfaces_sources,
+test_parsing_sources = [
+  'gcalc-parsing.vala',
+]
+
+test_parsing = executable('gcalc-parsing', test_parsing_sources,
+  dependencies:tests_deps,
+  link_with: [lib, lib_mpfrg],
+)
+test('gcalc-parsing', test_parsing)
+
+
+test_solve_basic_sources = [
+  'gcalc-solving-basic.vala',
+]
+
+test_solve_basic = executable('gcalc-solve-basic', test_solve_basic_sources,
   dependencies:tests_deps,
   link_with: [lib, lib_mpfrg],
 )
-test('gcalc-interfaces', test_interfaces)
+test('gcalc-solve-basic', test_solve_basic)


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