Пример #1
0
func TestComputeFormulaNestedParensFloat(t *testing.T) {
	formula := "(2.5*(2+5))+(2+(8-4))"

	if result, err := calc.ComputeFormula(formula); result != 23.5 {
		t.Errorf("ComputeFormula(\"(2.5*(2+5))+(2+(8-4))\"), expected: 23.5, actual: %v, error: %v", result, err)
	}
}
Пример #2
0
func TestComputeFormulaNestedParensDivisionFloat(t *testing.T) {
	formula := "((10*2)/5)"

	if result, err := calc.ComputeFormula(formula); result != 4 {
		t.Errorf("ComputeFormula(%v), expected: 4 actual: %v, error: %v", formula, result, err)
	}
}
Пример #3
0
func TestComputeFormulaAdditionParens(t *testing.T) {
	formula := "(2+2)+2"

	result, _ := calc.ComputeFormula(formula)

	if result != 6 {
		t.Error("expecting result: 6")
	}
}
Пример #4
0
func TestComputeFormulaAdditionMultiParensFloat(t *testing.T) {
	formula := "(2.5+2)+(2+8)"

	result, _ := calc.ComputeFormula(formula)

	if result != 14.5 {
		t.Error("expecting result: 14.5")
	}
}