algorithms/fundamentals/exrecises/math_evaluator/evaluator_test.go

31 lines
494 B
Go
Raw Permalink Normal View History

2021-11-08 22:58:25 +02:00
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)
}
}