algorithms/fundamentals/exrecises/math_evaluator/evaluator_test.go
2021-11-16 20:36:42 +02:00

30 lines
494 B
Go

package mathevaluator
import (
"log"
"testing"
)
func TestSimple(t *testing.T) {
result := Evaluate("( 1 + 1 )")
if result != 2 {
log.Fatalf("wrong answer: %v", result)
}
}
func TestSqrt(t *testing.T) {
result := Evaluate("sqrt ( 9 )")
if result != 3 {
log.Fatalf("wrong answer: %v", result)
}
}
func TestComplex(t *testing.T) {
result := Evaluate("( ( 1 + ( 2 - ( 3 * ( 4 / ( 1 + 1 ) ) ) ) ) + sqrt ( 9 ) )")
if result != 0 {
log.Fatalf("wrong answer: %v", result)
}
}