Move code out of cmd
This commit is contained in:
80
day1/main_test.go
Normal file
80
day1/main_test.go
Normal 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")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user