89 lines
1.8 KiB
Go
89 lines
1.8 KiB
Go
package tins2021
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func newFullHighscore() Highscores {
|
|
return Highscores{
|
|
NewScore(100, 100),
|
|
NewScore(90, 90),
|
|
NewScore(80, 80),
|
|
NewScore(70, 70),
|
|
NewScore(60, 60),
|
|
NewScore(50, 50),
|
|
NewScore(40, 40),
|
|
NewScore(30, 30),
|
|
NewScore(20, 20),
|
|
NewScore(10, 10),
|
|
}
|
|
}
|
|
|
|
func newHalfEmptyHighscore() Highscores {
|
|
return Highscores{
|
|
NewScore(100, 100),
|
|
NewScore(90, 90),
|
|
NewScore(80, 80),
|
|
NewScore(70, 70),
|
|
NewScore(60, 60),
|
|
}
|
|
}
|
|
|
|
func TestAddScoreBelowBottom(t *testing.T) {
|
|
h := newFullHighscore()
|
|
updated, high := h.AddScore(1, 1)
|
|
assert.False(t, high)
|
|
assert.Len(t, updated, 10)
|
|
for _, s := range h {
|
|
assert.Greater(t, s.Score, 1)
|
|
}
|
|
}
|
|
|
|
func TestAddScoreBottom(t *testing.T) {
|
|
h := newFullHighscore()
|
|
updated, high := h.AddScore(11, 11)
|
|
assert.True(t, high)
|
|
assert.Len(t, updated, 10)
|
|
assert.Equal(t, 11, updated[9].Score)
|
|
}
|
|
|
|
func TestAddScoreBottomNotFull(t *testing.T) {
|
|
h := Highscores{
|
|
NewScore(100, 100),
|
|
NewScore(90, 90),
|
|
NewScore(80, 80),
|
|
NewScore(70, 70),
|
|
}
|
|
|
|
updated, high := h.AddScore(50, 50)
|
|
assert.True(t, high)
|
|
assert.Len(t, updated, 5)
|
|
assert.Equal(t, 50, updated[4].Score)
|
|
}
|
|
|
|
func TestAddScoreMiddle(t *testing.T) {
|
|
h := newFullHighscore()
|
|
updated, high := h.AddScore(51, 51)
|
|
assert.True(t, high)
|
|
assert.Len(t, updated, 10)
|
|
assert.Equal(t, 51, updated[5].Score)
|
|
}
|
|
|
|
func TestAddScoreMiddleNotFull(t *testing.T) {
|
|
h := newHalfEmptyHighscore()
|
|
updated, high := h.AddScore(71, 71)
|
|
assert.True(t, high)
|
|
assert.Len(t, updated, 6)
|
|
assert.Equal(t, 71, updated[3].Score)
|
|
}
|
|
|
|
func TestAddScoreTop(t *testing.T) {
|
|
h := newFullHighscore()
|
|
updated, high := h.AddScore(101, 101)
|
|
assert.True(t, high)
|
|
assert.Len(t, updated, 10)
|
|
assert.Equal(t, 101, updated[0].Score)
|
|
}
|