You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.2 KiB
109 lines
3.2 KiB
package common_calc
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"log"
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func Test_formulaTemplate_demo1(t *testing.T) {
|
|
//公式表达式计算
|
|
formula := "(1.1*2 + 5/2)+ 2.4/2 + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo2(t *testing.T) {
|
|
//公式表达式计算
|
|
formula := "2² + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo3(t *testing.T) {
|
|
//公式表达式计算
|
|
formula := "(1.1*2 + 5/2)+ 2.4/2² + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo4(t *testing.T) {
|
|
//公式表达式计算 √
|
|
formula := "√4 + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo5(t *testing.T) {
|
|
//公式表达式计算 √
|
|
formula := "√4+12 + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
func Test_formulaTemplate_demo6(t *testing.T) {
|
|
//公式表达式计算 √
|
|
formula := "3*√4*5 + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo7(t *testing.T) {
|
|
//公式表达式计算 √
|
|
formula := "3*√(2*8) + 0.8"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo8(t *testing.T) {
|
|
//公式表达式计算 √
|
|
formula := "2*[1+2]+0.5"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
formula2 := "2*[3*(1+2)]+0.5"
|
|
result2 := CalculateFormula(formula2)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula2, result2)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo9(t *testing.T) {
|
|
formula := "sin(30*π/180)+cos(60*π/180)"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
func Test_formulaTemplate_demo10(t *testing.T) {
|
|
formula := "[sin(30*π/180)+1]+sin(60*π/180)"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
func Test_formulaTemplate_demo11(t *testing.T) {
|
|
formula := "[1+2³+3]"
|
|
result := CalculateFormula(formula)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
func Test_formulaTemplate_demo12(t *testing.T) {
|
|
formula := "1+2*π"
|
|
result := CalculateFormula(formula)
|
|
assert.Equal(t, result, 1+2*math.Pi)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
func Test_formulaTemplate_demo12_2(t *testing.T) {
|
|
formula := "1+2π"
|
|
result := CalculateFormula(formula)
|
|
assert.Equal(t, result, 1+2*math.Pi)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
func Test_formulaTemplate_demo13(t *testing.T) {
|
|
formula := "3^2+1"
|
|
result := CalculateFormula(formula)
|
|
assert.Equal(t, result, 10.0)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|
|
// -0.37-0
|
|
func Test_formulaTemplate_demo14(t *testing.T) {
|
|
formula := "-0.37-0"
|
|
result := CalculateFormula(formula)
|
|
assert.Equal(t, result, -0.37)
|
|
log.Printf("表达式 %s =>计算结果=%v", formula, result)
|
|
}
|
|
|