52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package content
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestAppearanceValidation(t *testing.T) {
|
|
base := Appearance{Version: 1, Family: "human", Variant: 0, Seed: 42, Height: 1, Width: 1, Detail: .5, Primary: "#d8a582", Secondary: "#493947", Accent: "#578f8b"}
|
|
if err := ValidateAppearance(&base, "human"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, mutate := range []func(*Appearance){
|
|
func(a *Appearance) { a.Family = "tree" }, func(a *Appearance) { a.Version = 2 },
|
|
func(a *Appearance) { a.Height = 100 }, func(a *Appearance) { a.Width = math.NaN() },
|
|
func(a *Appearance) { a.Detail = math.Inf(1) }, func(a *Appearance) { a.Variant = 4 },
|
|
func(a *Appearance) { a.Seed = 0 }, func(a *Appearance) { a.Primary = "url(bad)" },
|
|
} {
|
|
v := base
|
|
mutate(&v)
|
|
if ValidateAppearance(&v, "human") == nil {
|
|
t.Fatal("invalid appearance accepted", v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHumanoidAppearanceBounds(t *testing.T) {
|
|
base := DefaultCharacterAppearance()
|
|
if err := ValidateAppearance(base, "human"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, mutate := range []func(*Appearance){
|
|
func(a *Appearance) { a.Body.HeadWidth = math.NaN() },
|
|
func(a *Appearance) { a.Body.LegLength = 1.2 },
|
|
func(a *Appearance) { a.Body.NoseHeight = .1 },
|
|
func(a *Appearance) { a.Body.EyeColor = "red" },
|
|
func(a *Appearance) { a.Body.Eyebrows = "unknown" },
|
|
func(a *Appearance) { a.Body.Chest = "unknown" },
|
|
func(a *Appearance) { a.Body.MouthStyle = "unknown" },
|
|
func(a *Appearance) { a.Family = "creature" },
|
|
func(a *Appearance) { a.Width = 1.1 },
|
|
func(a *Appearance) { a.Body = nil },
|
|
func(a *Appearance) { a.Version = 1 },
|
|
} {
|
|
a := DefaultCharacterAppearance()
|
|
mutate(a)
|
|
if ValidateAppearance(a, "human", "creature") == nil {
|
|
t.Fatal("invalid anatomy accepted", a)
|
|
}
|
|
}
|
|
}
|