refactor: standardize code comments

This commit is contained in:
tinkle-community
2025-12-08 01:40:48 +08:00
parent 0636ced476
commit a12c0ae8c9
103 changed files with 5466 additions and 5468 deletions

View File

@@ -4,7 +4,7 @@ import (
"testing"
)
// TestLeverageFallback 测试杠杆超限时的自动修正功能
// TestLeverageFallback tests automatic correction when leverage exceeds limit
func TestLeverageFallback(t *testing.T) {
tests := []struct {
name string
@@ -12,47 +12,47 @@ func TestLeverageFallback(t *testing.T) {
accountEquity float64
btcEthLeverage int
altcoinLeverage int
wantLeverage int // 期望修正后的杠杆值
wantLeverage int // Expected leverage after correction
wantError bool
}{
{
name: "山寨币杠杆超限_自动修正为上限",
name: "Altcoin leverage exceeded - auto-correct to limit",
decision: Decision{
Symbol: "SOLUSDT",
Action: "open_long",
Leverage: 20, // 超过上限
Leverage: 20, // Exceeds limit
PositionSizeUSD: 100,
StopLoss: 50,
TakeProfit: 200,
},
accountEquity: 100,
btcEthLeverage: 10,
altcoinLeverage: 5, // 上限 5x
wantLeverage: 5, // 应该修正为 5
altcoinLeverage: 5, // Limit 5x
wantLeverage: 5, // Should be corrected to 5
wantError: false,
},
{
name: "BTC杠杆超限_自动修正为上限",
name: "BTC leverage exceeded - auto-correct to limit",
decision: Decision{
Symbol: "BTCUSDT",
Action: "open_long",
Leverage: 20, // 超过上限
Leverage: 20, // Exceeds limit
PositionSizeUSD: 1000,
StopLoss: 90000,
TakeProfit: 110000,
},
accountEquity: 100,
btcEthLeverage: 10, // 上限 10x
btcEthLeverage: 10, // Limit 10x
altcoinLeverage: 5,
wantLeverage: 10, // 应该修正为 10
wantLeverage: 10, // Should be corrected to 10
wantError: false,
},
{
name: "杠杆在上限内_不修正",
name: "Leverage within limit - no correction",
decision: Decision{
Symbol: "ETHUSDT",
Action: "open_short",
Leverage: 5, // 未超限
Leverage: 5, // Not exceeded
PositionSizeUSD: 500,
StopLoss: 4000,
TakeProfit: 3000,
@@ -60,15 +60,15 @@ func TestLeverageFallback(t *testing.T) {
accountEquity: 100,
btcEthLeverage: 10,
altcoinLeverage: 5,
wantLeverage: 5, // 保持不变
wantLeverage: 5, // Stays unchanged
wantError: false,
},
{
name: "杠杆为0_应该报错",
name: "Leverage is 0 - should error",
decision: Decision{
Symbol: "SOLUSDT",
Action: "open_long",
Leverage: 0, // 无效
Leverage: 0, // Invalid
PositionSizeUSD: 100,
StopLoss: 50,
TakeProfit: 200,
@@ -85,13 +85,13 @@ func TestLeverageFallback(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
err := validateDecision(&tt.decision, tt.accountEquity, tt.btcEthLeverage, tt.altcoinLeverage)
// 检查错误状态
// Check error status
if (err != nil) != tt.wantError {
t.Errorf("validateDecision() error = %v, wantError %v", err, tt.wantError)
return
}
// 如果不应该报错,检查杠杆是否被正确修正
// If shouldn't error, check if leverage was correctly corrected
if !tt.wantError && tt.decision.Leverage != tt.wantLeverage {
t.Errorf("Leverage not corrected: got %d, want %d", tt.decision.Leverage, tt.wantLeverage)
}
@@ -100,7 +100,7 @@ func TestLeverageFallback(t *testing.T) {
}
// contains 检查字符串是否包含子串(辅助函数)
// contains checks if string contains substring (helper function)
func contains(s, substr string) bool {
return len(s) >= len(substr) && (s == substr || len(substr) == 0 ||
(len(s) > 0 && len(substr) > 0 && stringContains(s, substr)))