Test a calc's operand list, one empty-segment check, and an empty segment after a step up

This commit is contained in:
2026-10-05 12:25:22 +02:00
committed by Lillem4n
parent 5e56b44dfa
commit 3479f9cf98
5 changed files with 26 additions and 16 deletions
+6 -6
View File
@@ -6,18 +6,18 @@ import (
)
func TestParseCalcPlacesEachOperandAtItsFirstReading(t *testing.T) {
n, err := ParseCalc("b * (a - b) / -2")
c, err := ParseCalc("b * (a - b) / -2")
if err != nil {
t.Fatal(err)
}
want := CalcBin{'/', CalcBin{'*', CalcVar{"b", 0}, CalcBin{'-', CalcVar{"a", 1}, CalcVar{"b", 0}}}, CalcNeg{CalcNum(2)}}
if !reflect.DeepEqual(n, want) {
t.Errorf("ParseCalc = %#v, want %#v", n, want)
if !reflect.DeepEqual(c.Expr, want) {
t.Errorf("ParseCalc = %#v, want %#v", c.Expr, want)
}
if got := CalcVars(n); !reflect.DeepEqual(got, []string{"b", "a"}) {
t.Errorf("CalcVars = %q, want [b a]", got)
if !reflect.DeepEqual(c.Operands, []string{"b", "a"}) {
t.Errorf("Operands = %q, want [b a]", c.Operands)
}
if got := CalcText(n); got != "((b * (a - b)) / -2)" {
if got := CalcText(c.Expr); got != "((b * (a - b)) / -2)" {
t.Errorf("CalcText = %q", got)
}
}