Skip to content

Commit

Permalink
Rename the Eval function to evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed May 14, 2022
1 parent c8772a4 commit b0a19cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit b0a19cf

Please sign in to comment.