-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheval_test.go
More file actions
31 lines (28 loc) · 762 Bytes
/
Copy patheval_test.go
File metadata and controls
31 lines (28 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package chili
import (
"fmt"
"testing"
"github.com/5anthosh/chili/environment"
"github.com/5anthosh/chili/evaluator"
"github.com/5anthosh/chili/parser"
)
func TestEvalNumberFunction(t *testing.T) {
source := "PI*R^2 + abs(45.345)"
env := environment.New()
env.SetDefaultFunctions()
env.SetDefaultVariables()
env.SetIntVariable("R", 2)
chiliParser := parser.New(source)
expression, err := chiliParser.Parse()
if err != nil {
t.Error(err)
}
chiliEvaluator := evaluator.New(env)
value, err := chiliEvaluator.Run(expression)
if err != nil {
t.Error(err)
}
if fmt.Sprintf("%v", value) != "57.91137061435917295385057353311801153678867759750042328389977836" {
t.Errorf("Evaluation = %s but want %s", fmt.Sprintf("%v", value), "57.905")
}
}