[gnome-calculator/60-split-out-a-backend-library] gcalc: fixed multiple function in polynomial



commit 8e88d0f6f6d9a85932a93a40f465e736615290e3
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Fri Jan 4 20:21:20 2019 -0600

    gcalc: fixed multiple function in polynomial

 gcalc/gcalc-function-acos.vala  | 5 +++--
 gcalc/gcalc-function-acosh.vala | 5 +++--
 gcalc/gcalc-function-asin.vala  | 5 +++--
 gcalc/gcalc-function-asinh.vala | 5 +++--
 gcalc/gcalc-function-atan.vala  | 5 +++--
 gcalc/gcalc-function-atanh.vala | 5 +++--
 gcalc/gcalc-function-cos.vala   | 5 +++--
 gcalc/gcalc-function-cosh.vala  | 5 +++--
 gcalc/gcalc-function-exp.vala   | 5 +++--
 gcalc/gcalc-function-log.vala   | 5 +++--
 gcalc/gcalc-function-sin.vala   | 5 +++--
 gcalc/gcalc-function-sinh.vala  | 5 +++--
 gcalc/gcalc-function-sqrt.vala  | 5 +++--
 gcalc/gcalc-function-tan.vala   | 5 +++--
 gcalc/gcalc-function-tanh.vala  | 5 +++--
 gcalc/gcalc-gfunction.vala      | 2 +-
 gcalc/gcalc-parser.vala         | 3 ++-
 tests/gcalc-solving-basic.vala  | 4 ++--
 18 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/gcalc/gcalc-function-acos.vala b/gcalc/gcalc-function-acos.vala
index ba62aee0..98197443 100644
--- a/gcalc/gcalc-function-acos.vala
+++ b/gcalc/gcalc-function-acos.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAcos : GFunction {
 
-  public GFunctionAcos () {
-    base ("acos", 1);
+  construct {
+    name = "acos";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-acosh.vala b/gcalc/gcalc-function-acosh.vala
index 2e78bd8f..fd0121ad 100644
--- a/gcalc/gcalc-function-acosh.vala
+++ b/gcalc/gcalc-function-acosh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAcosh : GFunction {
 
-  public GFunctionAcosh () {
-    base ("acosh", 1);
+  construct {
+    name = "acosh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-asin.vala b/gcalc/gcalc-function-asin.vala
index 74f8126a..b35a75c6 100644
--- a/gcalc/gcalc-function-asin.vala
+++ b/gcalc/gcalc-function-asin.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAsin : GFunction {
 
-  public GFunctionAsin () {
-    base ("asin", 1);
+  construct {
+    name = "asin";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-asinh.vala b/gcalc/gcalc-function-asinh.vala
index f98d2482..ffca07dc 100644
--- a/gcalc/gcalc-function-asinh.vala
+++ b/gcalc/gcalc-function-asinh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAsinh : GFunction {
 
-  public GFunctionAsinh () {
-    base ("asinh", 1);
+  construct {
+    name = "asinh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-atan.vala b/gcalc/gcalc-function-atan.vala
index f9f63f35..e38a7301 100644
--- a/gcalc/gcalc-function-atan.vala
+++ b/gcalc/gcalc-function-atan.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAtan : GFunction {
 
-  public GFunctionAtan () {
-    base ("atan", 1);
+  construct {
+    name = "atan";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-atanh.vala b/gcalc/gcalc-function-atanh.vala
index d57b0587..f0901865 100644
--- a/gcalc/gcalc-function-atanh.vala
+++ b/gcalc/gcalc-function-atanh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionAtanh : GFunction {
 
-  public GFunctionAtanh () {
-    base ("atanh", 1);
+  construct {
+    name = "atanh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-cos.vala b/gcalc/gcalc-function-cos.vala
index 27a5e200..7cc336cf 100644
--- a/gcalc/gcalc-function-cos.vala
+++ b/gcalc/gcalc-function-cos.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionCos : GFunction {
 
-  public GFunctionCos () {
-    base ("cos", 1);
+  construct {
+    name = "cos";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-cosh.vala b/gcalc/gcalc-function-cosh.vala
index f4671e0c..beb7a81a 100644
--- a/gcalc/gcalc-function-cosh.vala
+++ b/gcalc/gcalc-function-cosh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionCosh : GFunction {
 
-  public GFunctionCosh () {
-    base ("cosh", 1);
+  construct {
+    name = "cosh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-exp.vala b/gcalc/gcalc-function-exp.vala
index c0afba43..135d04e7 100644
--- a/gcalc/gcalc-function-exp.vala
+++ b/gcalc/gcalc-function-exp.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionExp : GFunction {
 
-  public GFunctionExp () {
-    base ("exp", 1);
+  construct {
+    name = "exp";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-log.vala b/gcalc/gcalc-function-log.vala
index bf8d7e0e..36a33ab8 100644
--- a/gcalc/gcalc-function-log.vala
+++ b/gcalc/gcalc-function-log.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionLog : GFunction {
 
-  public GFunctionLog () {
-    base ("log", 1);
+  construct {
+    name = "log";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-sin.vala b/gcalc/gcalc-function-sin.vala
index f0b694b3..f16c3c6c 100644
--- a/gcalc/gcalc-function-sin.vala
+++ b/gcalc/gcalc-function-sin.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionSin : GFunction {
 
-  public GFunctionSin () {
-    base ("sin", 1);
+  construct {
+    name = "sin";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-sinh.vala b/gcalc/gcalc-function-sinh.vala
index f7fe97ff..30ef98eb 100644
--- a/gcalc/gcalc-function-sinh.vala
+++ b/gcalc/gcalc-function-sinh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionSinh : GFunction {
 
-  public GFunctionSinh () {
-    base ("sinh", 1);
+  construct {
+    name = "sinh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-sqrt.vala b/gcalc/gcalc-function-sqrt.vala
index 1777b5c0..9dfd72ca 100644
--- a/gcalc/gcalc-function-sqrt.vala
+++ b/gcalc/gcalc-function-sqrt.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionSqrt : GFunction {
 
-  public GFunctionSqrt () {
-    base ("sqrt", 1);
+  construct {
+    name = "sqrt";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-tan.vala b/gcalc/gcalc-function-tan.vala
index ca62ca0e..0e74db06 100644
--- a/gcalc/gcalc-function-tan.vala
+++ b/gcalc/gcalc-function-tan.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionTan : GFunction {
 
-  public GFunctionTan () {
-    base ("tan", 1);
+  construct {
+    name = "tan";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-function-tanh.vala b/gcalc/gcalc-function-tanh.vala
index 13a531c1..8c34ed0d 100644
--- a/gcalc/gcalc-function-tanh.vala
+++ b/gcalc/gcalc-function-tanh.vala
@@ -20,8 +20,9 @@
  */
 public class GCalc.GFunctionTanh : GFunction {
 
-  public GFunctionTanh () {
-    base ("tanh", 1);
+  construct {
+    name = "tanh";
+    n_params = 1;
     param_types.add (new GConstant ());
   }
 
diff --git a/gcalc/gcalc-gfunction.vala b/gcalc/gcalc-gfunction.vala
index b2d1ba93..49b40f27 100644
--- a/gcalc/gcalc-gfunction.vala
+++ b/gcalc/gcalc-gfunction.vala
@@ -29,7 +29,7 @@ public class GCalc.GFunction : GExpression, Function {
   construct {
     name = "NoName";
   }
-  public GFunction (string name, int nparams) {
+  public GFunction.with_name (string name, int nparams) {
     this.name = name;
     n_params = nparams;
   }
diff --git a/gcalc/gcalc-parser.vala b/gcalc/gcalc-parser.vala
index 07a1acfe..9e8685b5 100644
--- a/gcalc/gcalc-parser.vala
+++ b/gcalc/gcalc-parser.vala
@@ -127,8 +127,9 @@ public class GCalc.Parser : Object {
         case Vala.TokenType.WHILE:
         case Vala.TokenType.YIELD:
         case Vala.TokenType.IDENTIFIER:
-          var sfunc = eqman.functions.find_named (n);
+          Expression sfunc = eqman.functions.find_named (n);
           if (sfunc != null) {
+            sfunc = Object.new (sfunc.get_type ()) as Expression;
             if (current == null) {
               var exp = new GPolynomial ();
               eq.expressions.add (exp);
diff --git a/tests/gcalc-solving-basic.vala b/tests/gcalc-solving-basic.vala
index 0983c14a..8c5aa34b 100644
--- a/tests/gcalc-solving-basic.vala
+++ b/tests/gcalc-solving-basic.vala
@@ -895,7 +895,7 @@ class Tests {
       try {
         var parser = new Parser ();
         var eqman = new GMathEquationManager ();
-        parser.parse ("9/3+5+2*cos(0)-9/cos(0)", eqman);
+        parser.parse ("2*cos(0)-9/cos(0)", eqman);
         assert (eqman.equations.get_n_items () == 1);
         var eq = eqman.equations.get_item (0) as MathEquation;
         assert (eq != null);
@@ -905,7 +905,7 @@ class Tests {
         var res = e.evaluate () as Constant;
         assert (res != null);
         message ("Constant Result: %s", res.to_string ());
-        assert (res.real () == 10.0);
+        assert (res.real () == -7.0);
       } catch (GLib.Error e) {
         warning ("Error: %s", e.message);
       }


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