57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package element
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetOffensiveMultiplierFromSeerTypesRelation(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
attackerID int
|
|
defenderID int
|
|
want float64
|
|
}{
|
|
{name: "single to single", attackerID: 1, defenderID: 2, want: 2},
|
|
{name: "immunity stays zero", attackerID: 5, defenderID: 7, want: 0},
|
|
{name: "single to double", attackerID: 3, defenderID: 43, want: 1.5},
|
|
{name: "double to single", attackerID: 35, defenderID: 7, want: 0.25},
|
|
{name: "double to double", attackerID: 92, defenderID: 223, want: 1.25},
|
|
{name: "new dual type ancient steel", attackerID: 129, defenderID: 223, want: 1.5},
|
|
{name: "new dual type ancient light", attackerID: 130, defenderID: 226, want: 1.25},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := Calculator.GetOffensiveMultiplier(tt.attackerID, tt.defenderID)
|
|
if err != nil {
|
|
t.Fatalf("GetOffensiveMultiplier() error = %v", err)
|
|
}
|
|
if math.Abs(got-tt.want) > 0.001 {
|
|
t.Fatalf("GetOffensiveMultiplier() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetCombinationIncludesSeerTypesRelationDualTypes(t *testing.T) {
|
|
tests := []struct {
|
|
id int
|
|
primary ElementType
|
|
secondary ElementType
|
|
}{
|
|
{id: 129, primary: ElementTypeSteel, secondary: ElementTypeAncient},
|
|
{id: 130, primary: ElementTypeLight, secondary: ElementTypeAncient},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
got, err := Calculator.GetCombination(tt.id)
|
|
if err != nil {
|
|
t.Fatalf("GetCombination(%d) error = %v", tt.id, err)
|
|
}
|
|
if got.Primary != tt.primary || got.Secondary == nil || *got.Secondary != tt.secondary {
|
|
t.Fatalf("GetCombination(%d) = %#v, want primary %v secondary %v", tt.id, got, tt.primary, tt.secondary)
|
|
}
|
|
}
|
|
}
|