staros/math_test.go
starainrt d93a851d1b
feat: 完善 staros 系统能力并更新 wincmd 发布版依赖
- 重构 sysconf 为文档模型 INI Parser 与 Config Framework
- 强化 hosts 解析、插入校验、写回与异常输入处理
- 完善 StarCmd 生命周期、等待 API、流式输出与 IO 重定向
- 扩展跨平台文件时间、文件锁、内存、进程与网络能力
- 将 Windows 进程适配更新到 b612.me/wincmd v0.1.0
- 移除本地 wincmd/win32api replace,改用发布版依赖
- 将最低 Go 版本提升到 1.18
- 补充 hosts、sysconf、FileLock、StarCmd 与平台适配回归测试
2026-06-09 18:10:19 +08:00

62 lines
1.2 KiB
Go

package staros
import (
"math"
"testing"
)
func TestCalcCompatibilityExpressions(t *testing.T) {
tests := []struct {
expr string
want float64
}{
{"1+2*3", 7},
{"(1+2)*3", 9},
{"60*60*24", 86400},
{"-1+2", 1},
{"sqrt(4)+abs(-3)", 5},
{"sin(pi/2)", 1},
{"arcsin(1)", math.Pi / 2},
{"asin(1)", math.Pi / 2},
{"loge(e)", 1},
{"ln(e)", 1},
{"log10(100)+log2(8)", 5},
{"floor(1.9)+ceil(1.1)+round(1.5)+trunc(1.9)", 6},
{"1.2e3+3", 1203},
{"pow(2,3)+hypot(3,4)", 13},
{"min(3,1,2)+max(3,1,2)", 4},
{"log(100)+rad(180)/pi+deg(pi)/180", 4},
{"cbrt(27)+exp(0)", 4},
{"sinh(0)+cosh(0)+tanh(0)", 1},
}
for _, tt := range tests {
got, err := Calc(tt.expr)
if err != nil {
t.Fatalf("Calc(%q) failed: %v", tt.expr, err)
}
if math.Abs(got-tt.want) > 1e-12 {
t.Fatalf("Calc(%q)=%v, want %v", tt.expr, got, tt.want)
}
}
}
func TestCalcRejectsInvalidExpressions(t *testing.T) {
tests := []string{
"",
"1/",
"(1+2",
"1/0",
"unknown(1)",
"min()",
"pow(2)",
"pow(2,3,4)",
"sqrt(1,2)",
"pi()",
}
for _, expr := range tests {
if got, err := Calc(expr); err == nil {
t.Fatalf("Calc(%q)=%v, expected error", expr, got)
}
}
}