Skip to content

Commit df99366

Browse files
committed
feat: improve tangent handling in calculator and add separator mode setup in tests
1 parent c42ec25 commit df99366

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

wox.core/plugin/system/calculator/calculator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func call(funcName string, args []decimal.Decimal) (decimal.Decimal, error) {
7575
if result == 1 || result == -1 {
7676
result = f(math.Nextafter(x, 0))
7777
}
78+
if math.Abs(result-1) < 1e-12 {
79+
result = 1
80+
} else if math.Abs(result+1) < 1e-12 {
81+
result = -1
82+
}
7883
return decimal.NewFromFloat(result), nil
7984
}
8085
return decimal.NewFromFloat(f(args[0].InexactFloat64())), nil

wox.core/test/calculator_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@ import (
55
"wox/plugin"
66
)
77

8+
const calculatorPluginID = "bd723c38-f28d-4152-8621-76fd21d6456e"
9+
10+
func setCalculatorSeparatorMode(t *testing.T, mode string) {
11+
t.Helper()
12+
var calcInstance *plugin.Instance
13+
for _, instance := range plugin.GetPluginManager().GetPluginInstances() {
14+
if instance.Metadata.Id == calculatorPluginID {
15+
calcInstance = instance
16+
break
17+
}
18+
}
19+
if calcInstance == nil {
20+
t.Fatal("Calculator plugin instance not found")
21+
}
22+
if err := calcInstance.Setting.Set("SeparatorMode", mode); err != nil {
23+
t.Fatalf("Failed to set separator mode: %v", err)
24+
}
25+
}
26+
827
func TestCalculatorBasic(t *testing.T) {
928
suite := NewTestSuite(t)
29+
setCalculatorSeparatorMode(t, "Dot")
1030

1131
tests := []QueryTest{
1232
{
@@ -88,6 +108,7 @@ func TestCalculatorBasic(t *testing.T) {
88108

89109
func TestCalculatorTrigonometric(t *testing.T) {
90110
suite := NewTestSuite(t)
111+
setCalculatorSeparatorMode(t, "Dot")
91112

92113
tests := []QueryTest{
93114
{
@@ -117,7 +138,7 @@ func TestCalculatorTrigonometric(t *testing.T) {
117138
{
118139
Name: "Tangent",
119140
Query: "tan(pi/4)",
120-
ExpectedTitle: "0.9999999999999998",
141+
ExpectedTitle: "1",
121142
ExpectedAction: "Copy",
122143
},
123144
}
@@ -127,6 +148,7 @@ func TestCalculatorTrigonometric(t *testing.T) {
127148

128149
func TestCalculatorAdvanced(t *testing.T) {
129150
suite := NewTestSuite(t)
151+
setCalculatorSeparatorMode(t, "Dot")
130152

131153
tests := []QueryTest{
132154
{
@@ -244,6 +266,7 @@ func TestCalculatorAdvanced(t *testing.T) {
244266

245267
func TestCalculatorSeparators(t *testing.T) {
246268
suite := NewTestSuite(t)
269+
setCalculatorSeparatorMode(t, "Dot")
247270
calculatorId := "bd723c38-f28d-4152-8621-76fd21d6456e"
248271

249272
// Find the plugin instance to ensure we update the correct setting store

0 commit comments

Comments
 (0)