1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-14 19:22:27 +00:00

refactor: use builtin max instead of maxInt (#430)

This commit is contained in:
Oleksandr Redko
2026-02-10 08:27:00 +02:00
committed by GitHub
parent 386f2b3534
commit 599b39a3fb
3 changed files with 2 additions and 35 deletions

View File

@@ -142,7 +142,7 @@ func (m model) View() string {
header := renderHeader(m.metrics, m.errMessage, m.animFrame, m.width, m.catHidden) header := renderHeader(m.metrics, m.errMessage, m.animFrame, m.width, m.catHidden)
cardWidth := 0 cardWidth := 0
if m.width > 80 { if m.width > 80 {
cardWidth = maxInt(24, m.width/2-4) cardWidth = max(24, m.width/2-4)
} }
cards := buildCards(m.metrics, cardWidth) cards := buildCards(m.metrics, cardWidth)

View File

@@ -763,7 +763,7 @@ func renderTwoColumns(cards []cardData, width int) string {
if i+1 < len(cards) { if i+1 < len(cards) {
right = renderCard(cards[i+1], cw, 0) right = renderCard(cards[i+1], cw, 0)
} }
targetHeight := maxInt(lipgloss.Height(left), lipgloss.Height(right)) targetHeight := max(lipgloss.Height(left), lipgloss.Height(right))
left = renderCard(cards[i], cw, targetHeight) left = renderCard(cards[i], cw, targetHeight)
if right != "" { if right != "" {
right = renderCard(cards[i+1], cw, targetHeight) right = renderCard(cards[i+1], cw, targetHeight)
@@ -782,10 +782,3 @@ func renderTwoColumns(cards []cardData, width int) string {
} }
return lipgloss.JoinVertical(lipgloss.Left, spacedRows...) return lipgloss.JoinVertical(lipgloss.Left, spacedRows...)
} }
func maxInt(a, b int) int {
if a > b {
return a
}
return b
}

View File

@@ -822,32 +822,6 @@ func TestGetScoreStyle(t *testing.T) {
} }
} }
func TestMaxInt(t *testing.T) {
tests := []struct {
name string
a int
b int
want int
}{
{"a greater", 10, 5, 10},
{"b greater", 3, 8, 8},
{"equal", 7, 7, 7},
{"negative a greater", -5, -10, -5},
{"negative b greater", -10, -5, -5},
{"zero vs positive", 0, 5, 5},
{"zero vs negative", 0, -5, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := maxInt(tt.a, tt.b)
if got != tt.want {
t.Errorf("maxInt(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.want)
}
})
}
}
func TestSparkline(t *testing.T) { func TestSparkline(t *testing.T) {
tests := []struct { tests := []struct {
name string name string