diff --git a/main.go b/main.go index 2e8d2ad..d7dde4e 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,8 @@ func get(qs map[string][]Quote, t string) Quote { if len(qs[t]) != 1 { rand.Seed(time.Now().Unix()) quote = qs[t][rand.Intn(len(qs[t]))] + } else { + quote = qs[t][0] } } diff --git a/main_test.go b/main_test.go index 2d5b098..a97ead9 100644 --- a/main_test.go +++ b/main_test.go @@ -26,3 +26,23 @@ func TestDecorate(t *testing.T) { } } } + +func TestGet(t *testing.T) { + tables := []struct { + m map[string][]Quote + q Quote + }{ + { + map[string][]Quote{"00:00": { + Quote{"Max Mustermann", "Testbook", "This is a time!", "time"}, + }}, + Quote{"Max Mustermann", "Testbook", "This is a time!", "time"}, + }, + } + for _, table := range tables { + q := get(table.m, "00:00") + if q != table.q { + t.Errorf("quote \"%+v\" is not like \"%+v\"", q, table.q) + } + } +}