Add character levels and permanent player titles
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProgressionAndTitleValidation(t *testing.T) {
|
||||
for name, mutate := range map[string]func(*Balance){
|
||||
"missing progression": func(b *Balance) { b.Progression = nil },
|
||||
"zero threshold": func(b *Balance) { b.Progression.BaseXP = 0 },
|
||||
"negative growth": func(b *Balance) { b.Progression.XPPerLevel = -1 },
|
||||
"point grant": func(b *Balance) { b.Progression.StatPointsPerLevel = 0 },
|
||||
"overflow curve": func(b *Balance) { b.Progression.BaseXP = math.MaxInt64 },
|
||||
"unbounded cap": func(b *Balance) { b.Progression.MaxLevel = math.MaxInt64 },
|
||||
"negative reward": func(b *Balance) { b.Progression.GatherXP = -1 },
|
||||
"duplicate title": func(b *Balance) { b.Titles = append(b.Titles, b.Titles[0]) },
|
||||
"bad scope": func(b *Balance) { b.Titles[0].Scope = "client" },
|
||||
"no requirements": func(b *Balance) { b.Titles[0].Requirements = nil },
|
||||
"unknown metric": func(b *Balance) { b.Titles[0].Requirements[0].Metric = "clientXp" },
|
||||
"invalid threshold": func(b *Balance) { b.Titles[0].Requirements[0].AtLeast = 0 },
|
||||
"infinite effect": func(b *Balance) { b.Titles[0].Effects.Damage = math.Inf(1) },
|
||||
"nan effect": func(b *Balance) { b.Titles[0].Effects.MoveSpeed = math.NaN() },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
b, err := Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mutate(&b)
|
||||
if b.Validate() == nil {
|
||||
t.Fatal("invalid content accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
b, _ := Load()
|
||||
b.Titles[0].Effects.Damage = -5
|
||||
b.Titles[0].Effects.MoveSpeed = -1
|
||||
b.Progression.GatherXP = 0
|
||||
if err := b.Validate(); err != nil {
|
||||
t.Fatalf("valid penalty or disabled reward rejected: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user