2018-09-14 18:24:48 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-10 20:50:03 -06:00
|
|
|
"sort"
|
2020-08-14 20:26:04 -06:00
|
|
|
"testing"
|
2018-09-14 18:24:48 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAward(t *testing.T) {
|
|
|
|
entry := "1536958399 1a2b3c4d counting 1"
|
|
|
|
a, err := ParseAward(entry)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2020-08-14 20:26:04 -06:00
|
|
|
if a.TeamID != "1a2b3c4d" {
|
2018-09-14 18:24:48 -06:00
|
|
|
t.Error("TeamID parsed wrong")
|
|
|
|
}
|
|
|
|
if a.Category != "counting" {
|
|
|
|
t.Error("Category parsed wrong")
|
|
|
|
}
|
|
|
|
if a.Points != 1 {
|
|
|
|
t.Error("Points parsed wrong")
|
|
|
|
}
|
2018-09-17 17:00:08 -06:00
|
|
|
|
2018-09-14 18:24:48 -06:00
|
|
|
if a.String() != entry {
|
|
|
|
t.Error("String conversion wonky")
|
|
|
|
}
|
2018-09-17 17:00:08 -06:00
|
|
|
|
2020-02-29 18:36:59 -07:00
|
|
|
if ja, err := a.MarshalJSON(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
} else if string(ja) != `[1536958399,"1a2b3c4d","counting",1]` {
|
|
|
|
t.Error("JSON wrong")
|
|
|
|
}
|
2020-02-29 22:37:22 -07:00
|
|
|
|
2018-09-14 18:24:48 -06:00
|
|
|
if _, err := ParseAward("bad bad bad 1"); err == nil {
|
|
|
|
t.Error("Not throwing error on bad timestamp")
|
|
|
|
}
|
|
|
|
if _, err := ParseAward("1 bad bad bad"); err == nil {
|
|
|
|
t.Error("Not throwing error on bad points")
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 20:50:03 -06:00
|
|
|
|
|
|
|
func TestAwardList(t *testing.T) {
|
2020-08-14 20:26:04 -06:00
|
|
|
a, _ := ParseAward("1536958399 1a2b3c4d counting 1")
|
|
|
|
b, _ := ParseAward("1536958400 1a2b3c4d counting 1")
|
|
|
|
c, _ := ParseAward("1536958300 1a2b3c4d counting 1")
|
|
|
|
list := AwardList{a, b, c}
|
|
|
|
|
|
|
|
if sort.IsSorted(list) {
|
|
|
|
t.Error("Unsorted list thinks it's sorted")
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Stable(list)
|
|
|
|
if (list[0] != c) || (list[1] != a) || (list[2] != b) {
|
|
|
|
t.Error("Sorting didn't")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !sort.IsSorted(list) {
|
|
|
|
t.Error("Sorted list thinks it isn't")
|
|
|
|
}
|
2020-03-10 20:50:03 -06:00
|
|
|
}
|