31 lines
494 B
Go
31 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)
|
||
|
}
|
||
|
}
|