You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/denisovdennis/autohero/internal/model"
|
|
)
|
|
|
|
func TestFilterCapOfferableQuests_filtersTaken(t *testing.T) {
|
|
all := []model.Quest{
|
|
{ID: 1, Title: "a"},
|
|
{ID: 2, Title: "b"},
|
|
{ID: 3, Title: "c"},
|
|
}
|
|
taken := map[int64]struct{}{2: {}}
|
|
out := FilterCapOfferableQuests(all, taken, 10, 42)
|
|
if len(out) != 2 {
|
|
t.Fatalf("len=%d want 2", len(out))
|
|
}
|
|
for _, q := range out {
|
|
if q.ID == 2 {
|
|
t.Fatal("taken quest should be removed")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFilterCapOfferableQuests_capDeterministic(t *testing.T) {
|
|
all := []model.Quest{
|
|
{ID: 10, Title: "a"},
|
|
{ID: 20, Title: "b"},
|
|
{ID: 30, Title: "c"},
|
|
}
|
|
out1 := FilterCapOfferableQuests(all, nil, 2, 999)
|
|
out2 := FilterCapOfferableQuests(all, nil, 2, 999)
|
|
if len(out1) != 2 || len(out2) != 2 {
|
|
t.Fatalf("cap: len1=%d len2=%d", len(out1), len(out2))
|
|
}
|
|
if out1[0].ID != out2[0].ID || out1[1].ID != out2[1].ID {
|
|
t.Fatalf("same seed should produce same order: %#v vs %#v", out1, out2)
|
|
}
|
|
_ = FilterCapOfferableQuests(all, nil, 2, 1000)
|
|
}
|
|
|
|
func TestFilterCapOfferableQuests_limitZeroReturnsAll(t *testing.T) {
|
|
all := []model.Quest{{ID: 1}, {ID: 2}}
|
|
out := FilterCapOfferableQuests(all, nil, 0, 1)
|
|
if len(out) != 2 {
|
|
t.Fatalf("len=%d want 2", len(out))
|
|
}
|
|
}
|