82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestCritTier(t *testing.T) {
|
|
cases := []struct {
|
|
rating, want int
|
|
}{{-1, 0}, {0, 0}, {1, 1}, {2, 2}, {3, 2}, {5, 2}}
|
|
for _, c := range cases {
|
|
if got := critTier(c.rating); got != c.want {
|
|
t.Errorf("critTier(%d) = %d, want %d", c.rating, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAllowedCritSet(t *testing.T) {
|
|
for _, vals := range [][]int{nil, {}, {0, 1, 2}, {0, 1, 3}} {
|
|
if allowedCritSet(vals) != nil {
|
|
t.Errorf("allowedCritSet(%v) should be nil (inactive)", vals)
|
|
}
|
|
}
|
|
if s := allowedCritSet([]int{1}); s == nil || !s[1] || s[0] || s[2] {
|
|
t.Errorf("allowedCritSet({1}) = %v, want only tier 1", s)
|
|
}
|
|
if s := allowedCritSet([]int{0, 1}); s == nil || !s[0] || !s[1] || s[2] {
|
|
t.Errorf("allowedCritSet({0,1}) = %v, want tiers 0,1", s)
|
|
}
|
|
if s := allowedCritSet([]int{3}); s == nil || !s[2] || s[0] || s[1] {
|
|
t.Errorf("allowedCritSet({3}) = %v, want only tier 2 (normalized)", s)
|
|
}
|
|
}
|
|
|
|
func TestIsArmorSlot(t *testing.T) {
|
|
for _, s := range []string{"Chest", "Head", "Feet", "Chest, Abdomen", "Upper Legs, Lower Legs"} {
|
|
if !isArmorSlot(s) {
|
|
t.Errorf("isArmorSlot(%q) = false, want true", s)
|
|
}
|
|
}
|
|
for _, s := range []string{"Neck", "Left Ring", "Left Wrist", "Trinket", "Shirt", "Pants", "Unknown", ""} {
|
|
if isArmorSlot(s) {
|
|
t.Errorf("isArmorSlot(%q) = true, want false", s)
|
|
}
|
|
}
|
|
}
|
|
|
|
func cdItem(slot string, cd int) *SuitItem {
|
|
return &SuitItem{Slot: slot, Ratings: map[string]int{"crit_damage_rating": cd}}
|
|
}
|
|
|
|
func TestFilterArmorByCD(t *testing.T) {
|
|
items := []*SuitItem{
|
|
cdItem("Chest", 0), cdItem("Head", 1), cdItem("Feet", 2),
|
|
cdItem("Chest, Abdomen", 2), // multi-coverage armor, CD2
|
|
cdItem("Neck", 0), // jewelry — never filtered
|
|
cdItem("Shirt", 0), // clothing — never filtered
|
|
}
|
|
|
|
if got := filterArmorByCD(items, nil); len(got) != len(items) {
|
|
t.Errorf("nil filter dropped items: got %d, want %d", len(got), len(items))
|
|
}
|
|
|
|
got := filterArmorByCD(items, map[int]bool{1: true})
|
|
keep := map[string]bool{"Head": true, "Neck": true, "Shirt": true}
|
|
if len(got) != 3 {
|
|
t.Fatalf("allowed{1}: got %d items, want 3", len(got))
|
|
}
|
|
for _, it := range got {
|
|
if !keep[it.Slot] {
|
|
t.Errorf("allowed{1}: unexpected slot %q survived", it.Slot)
|
|
}
|
|
}
|
|
|
|
got = filterArmorByCD(items, map[int]bool{0: true, 1: true})
|
|
if len(got) != 4 { // Chest(0), Head(1), Neck, Shirt
|
|
t.Errorf("allowed{0,1}: got %d items, want 4", len(got))
|
|
}
|
|
for _, it := range got {
|
|
if isArmorSlot(it.Slot) && it.Ratings["crit_damage_rating"] >= 2 {
|
|
t.Errorf("allowed{0,1}: CD2 armor %q should have been dropped", it.Slot)
|
|
}
|
|
}
|
|
}
|