Automated parts sorting
This commit is contained in:
@@ -10525,6 +10525,72 @@ func TestAugmentWithAutogeneratedPartsRespectsExistingIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePartsRowsACBonusUsesConfiguredPolicyBeforeOverrides(t *testing.T) {
|
||||
collected := []nativeCollectedDataset{
|
||||
{
|
||||
Dataset: nativeDataset{Name: "parts/belt", OutputName: "parts_belt.2da"},
|
||||
Columns: []string{"COSTMODIFIER", "ACBONUS"},
|
||||
Rows: []map[string]any{
|
||||
{"id": 1, "COSTMODIFIER": "5", "ACBONUS": "0.90"},
|
||||
{"id": 999, "COSTMODIFIER": "0", "ACBONUS": "****"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Dataset: nativeDataset{Name: "parts/chest", OutputName: "parts_chest.2da"},
|
||||
Columns: []string{"COSTMODIFIER", "ACBONUS"},
|
||||
Rows: []map[string]any{
|
||||
{"id": 14, "COSTMODIFIER": "0", "ACBONUS": "8.00"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Dataset: nativeDataset{Name: "parts/robe", OutputName: "parts_robe.2da"},
|
||||
Columns: []string{"COSTMODIFIER", "ACBONUS"},
|
||||
Rows: []map[string]any{
|
||||
{"id": 95, "COSTMODIFIER": "0", "ACBONUS": "0.00"},
|
||||
},
|
||||
},
|
||||
}
|
||||
cfg := project.PartsRowsConfig{
|
||||
RowDefaults: map[string]string{"COSTMODIFIER": "0"},
|
||||
ACBonus: project.PartsRowsACBonusConfig{
|
||||
Default: project.PartsRowsACBonusPolicy{Strategy: "descending_row_id_sort_key", MaxRowID: 999, Divisor: 100, Format: "%.2f"},
|
||||
Datasets: map[string]project.PartsRowsACBonusPolicy{
|
||||
"chest": {Strategy: "fixed", Value: "0.00"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
got, err := normalizePartsRowsACBonus(collected, cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("normalizePartsRowsACBonus failed: %v", err)
|
||||
}
|
||||
|
||||
beltRows := rowsByID(got[0].Rows)
|
||||
if got := beltRows[1]["ACBONUS"]; got != "9.98" {
|
||||
t.Fatalf("expected authored belt ACBONUS to be replaced with computed sort key 9.98, got %v", got)
|
||||
}
|
||||
if got := beltRows[999]["ACBONUS"]; got != "0.00" {
|
||||
t.Fatalf("expected highest belt row to sort at 0.00, got %v", got)
|
||||
}
|
||||
chestRows := rowsByID(got[1].Rows)
|
||||
if got := chestRows[14]["ACBONUS"]; got != "0.00" {
|
||||
t.Fatalf("expected chest ACBONUS to be forced to 0.00, got %v", got)
|
||||
}
|
||||
robeRows := rowsByID(got[2].Rows)
|
||||
if got := robeRows[95]["ACBONUS"]; got != "9.04" {
|
||||
t.Fatalf("expected robe to use computed non-chest sort key, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func rowsByID(rows []map[string]any) map[int]map[string]any {
|
||||
out := map[int]map[string]any{}
|
||||
for _, row := range rows {
|
||||
id, _ := row["id"].(int)
|
||||
out[id] = row
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestAugmentWithAutogeneratedPartsSortsRows(t *testing.T) {
|
||||
collected := []nativeCollectedDataset{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user