Move code out of cmd

This commit is contained in:
2025-12-03 23:03:27 +02:00
parent 1d458af093
commit 9b17ee26b9
16 changed files with 1 additions and 1 deletions

80
day1/main_test.go Normal file
View File

@@ -0,0 +1,80 @@
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_dial_Add2(t *testing.T) {
tests := []struct {
start int
turn int
want int
wantClicks int
}{
{
start: 50,
turn: 300,
want: 50,
wantClicks: 3,
},
{
start: 50,
turn: -300,
want: 50,
wantClicks: 3,
},
{
start: 0,
turn: -100,
want: 0,
wantClicks: 1,
},
{
start: 1,
turn: -101,
want: 0,
wantClicks: 2,
},
{
start: 99,
turn: -199,
want: 0,
wantClicks: 2,
},
{
start: 0,
turn: 100,
want: 0,
wantClicks: 1,
},
{
start: 99,
turn: 101,
want: 0,
wantClicks: 2,
},
{
start: 1,
turn: 199,
want: 0,
wantClicks: 2,
},
}
for _, tt := range tests {
name := fmt.Sprintf("R%d", tt.turn)
if tt.turn < 0 {
name = fmt.Sprintf("L%d", -tt.turn)
}
t.Run(name, func(t *testing.T) {
d := dial{n: tt.start}
d.Add2(tt.turn)
assert.Equal(t, tt.want, d.n, "dial")
assert.Equal(t, tt.wantClicks, d.zeroClicks, "clicks")
})
}
}