From b0a19cfcf844e3f3daf266f6ef61ebbdd63d5758 Mon Sep 17 00:00:00 2001 From: Jacob Alzen Date: Sat, 14 May 2022 11:59:09 +0200 Subject: [PATCH] Rename the Eval function to evaluate --- eval.go | 4 ++-- eval_test.go | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/eval.go b/eval.go index d6604c0..20f5136 100644 --- a/eval.go +++ b/eval.go @@ -37,8 +37,8 @@ func evaluateRPN(tokens []string) (float64, error) { return stack[0], nil } -// Eval evaluates the mathematical expression and returns the result. -func Eval(input string) (float64, error) { +// Evaluate evaluates the mathematical expression and returns the result. +func Evaluate(input string) (float64, error) { rpn, err := infixToRPN(input) if err != nil { return 0, err diff --git a/eval_test.go b/eval_test.go index 9eaadea..b6f1165 100644 --- a/eval_test.go +++ b/eval_test.go @@ -2,11 +2,11 @@ package eval import "testing" -func TestEval_Addition(t *testing.T) { +func TestEvaluate_Addition(t *testing.T) { input := "5 + 3 + 12 + -10" expected := 10.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -16,11 +16,11 @@ func TestEval_Addition(t *testing.T) { } } -func TestEval_Subtraction(t *testing.T) { +func TestEvaluate_Subtraction(t *testing.T) { input := "24 - 12 - -2" expected := 14.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -30,11 +30,11 @@ func TestEval_Subtraction(t *testing.T) { } } -func TestEval_Multiplication(t *testing.T) { +func TestEvaluate_Multiplication(t *testing.T) { input := "0.5 * 60 * 3" expected := 90.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -44,11 +44,11 @@ func TestEval_Multiplication(t *testing.T) { } } -func TestEval_Division(t *testing.T) { +func TestEvaluate_Division(t *testing.T) { input := "15 / 0.5 / 6" expected := 5.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -58,11 +58,11 @@ func TestEval_Division(t *testing.T) { } } -func TestEval_Power(t *testing.T) { +func TestEvaluate_Power(t *testing.T) { input := "2 ^ 3" expected := 8.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -72,11 +72,11 @@ func TestEval_Power(t *testing.T) { } } -func TestEval_Parenthesis(t *testing.T) { +func TestEvaluate_Parenthesis(t *testing.T) { input := "-5 + 5 * ( 7 - 2 )" expected := 20.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) } @@ -86,11 +86,11 @@ func TestEval_Parenthesis(t *testing.T) { } } -func TestEval_All(t *testing.T) { +func TestEvaluate_All(t *testing.T) { input := "( 6 - 2 * ( 6 / 3 ) ) ^ 3" expected := 8.0 - actual, err := Eval(input) + actual, err := Evaluate(input) if err != nil { t.Error(err) }