Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 76 additions & 48 deletions src/validation/highscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,80 @@ func TestHighscoreCategoryInvalidValueString(t *testing.T) {
func TestHighscoreCategoryFromString(t *testing.T) {
assert := assert.New(t)

assert.Equal(HighScoreExperience, HighscoreCategoryFromString("experience"))
assert.Equal(HighScoreExperience, HighscoreCategoryFromString(""))

assert.Equal(HighScoreAchievements, HighscoreCategoryFromString("achievements"))
assert.Equal(HighScoreAchievements, HighscoreCategoryFromString("achievement"))

assert.Equal(HighScoreAxefighting, HighscoreCategoryFromString("axe"))
assert.Equal(HighScoreAxefighting, HighscoreCategoryFromString("axefighting"))

assert.Equal(HighScoreCharmpoints, HighscoreCategoryFromString("charm"))
assert.Equal(HighScoreCharmpoints, HighscoreCategoryFromString("charms"))
assert.Equal(HighScoreCharmpoints, HighscoreCategoryFromString("charmpoints"))
assert.Equal(HighScoreCharmpoints, HighscoreCategoryFromString("charmspoints"))

assert.Equal(HighScoreClubfighting, HighscoreCategoryFromString("club"))
assert.Equal(HighScoreClubfighting, HighscoreCategoryFromString("clubfighting"))

assert.Equal(HighScoreDistancefighting, HighscoreCategoryFromString("distance"))
assert.Equal(HighScoreDistancefighting, HighscoreCategoryFromString("distancefighting"))

assert.Equal(HighScoreFishing, HighscoreCategoryFromString("fishing"))

assert.Equal(HighScoreFistfighting, HighscoreCategoryFromString("fist"))
assert.Equal(HighScoreFistfighting, HighscoreCategoryFromString("fistfighting"))

assert.Equal(HighScoreGoshnarstaint, HighscoreCategoryFromString("goshnar"))
assert.Equal(HighScoreGoshnarstaint, HighscoreCategoryFromString("goshnars"))
assert.Equal(HighScoreGoshnarstaint, HighscoreCategoryFromString("goshnarstaint"))

assert.Equal(HighScoreLoyaltypoints, HighscoreCategoryFromString("loyalty"))
assert.Equal(HighScoreLoyaltypoints, HighscoreCategoryFromString("loyaltypoints"))

assert.Equal(HighScoreMagiclevel, HighscoreCategoryFromString("magic"))
assert.Equal(HighScoreMagiclevel, HighscoreCategoryFromString("mlvl"))
assert.Equal(HighScoreMagiclevel, HighscoreCategoryFromString("magiclevel"))

assert.Equal(HighScoreShielding, HighscoreCategoryFromString("shielding"))
assert.Equal(HighScoreShielding, HighscoreCategoryFromString("shield"))

assert.Equal(HighScoreSwordfighting, HighscoreCategoryFromString("sword"))
assert.Equal(HighScoreSwordfighting, HighscoreCategoryFromString("swordfighting"))

assert.Equal(HighScoreDromescore, HighscoreCategoryFromString("drome"))
assert.Equal(HighScoreDromescore, HighscoreCategoryFromString("dromescore"))

assert.Equal(HighScoreBosspoints, HighscoreCategoryFromString("boss"))
assert.Equal(HighScoreBosspoints, HighscoreCategoryFromString("bosses"))
assert.Equal(HighScoreBosspoints, HighscoreCategoryFromString("bosspoints"))
categoryTests := map[string]struct {
inputs []string
expected HighscoreCategory
}{
"Experience": {
inputs: []string{"experience", ""},
expected: HighScoreExperience,
},
"Achievements": {
inputs: []string{"achievements", "achievement"},
expected: HighScoreAchievements,
},
"Axefighting": {
inputs: []string{"axe", "axefighting"},
expected: HighScoreAxefighting,
},
"Charmpoints": {
inputs: []string{"charm", "charms", "charmpoints", "charmspoints"},
expected: HighScoreCharmpoints,
},
"Clubfighting": {
inputs: []string{"club", "clubfighting"},
expected: HighScoreClubfighting,
},
"Distancefighting": {
inputs: []string{"distance", "distancefighting"},
expected: HighScoreDistancefighting,
},
"Fishing": {
inputs: []string{"fishing"},
expected: HighScoreFishing,
},
"Fistfighting": {
inputs: []string{"fist", "fistfighting"},
expected: HighScoreFistfighting,
},
"Goshnarstaint": {
inputs: []string{"goshnar", "goshnars", "goshnarstaint"},
expected: HighScoreGoshnarstaint,
},
"Loyaltypoints": {
inputs: []string{"loyalty", "loyaltypoints"},
expected: HighScoreLoyaltypoints,
},
"Magiclevel": {
inputs: []string{"magic", "mlvl", "magiclevel"},
expected: HighScoreMagiclevel,
},
"Shielding": {
inputs: []string{"shielding", "shield"},
expected: HighScoreShielding,
},
"Swordfighting": {
inputs: []string{"sword", "swordfighting"},
expected: HighScoreSwordfighting,
},
"Dromescore": {
inputs: []string{"drome", "dromescore"},
expected: HighScoreDromescore,
},
"Bosspoints": {
inputs: []string{"boss", "bosses", "bosspoints"},
expected: HighScoreBosspoints,
},
}

for category, data := range categoryTests {
t.Run(category, func(t *testing.T) {
for _, input := range data.inputs {
t.Run(input, func(t *testing.T) {
result := HighscoreCategoryFromString(input)
assert.Equal(data.expected, result, "unexpected result for input: %s", input)
})
}
})
}
}
112 changes: 39 additions & 73 deletions src/validation/tibia_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package validation

import "testing"
import (
"fmt"
"testing"
)

func TestTownExists(t *testing.T) {
if !initiated {
Expand All @@ -10,94 +13,57 @@ func TestTownExists(t *testing.T) {
}
}

tests := []struct {
name string
town string
// Define test data with expected results
testData := map[string]struct {
towns []string
want bool
wantErr bool
}{
{
name: "empty",
town: "",
"empty": {
towns: []string{""},
want: false,
wantErr: false,
}, {
name: "unknown",
town: "anything",
},
"unknown": {
towns: []string{"anything"},
want: false,
wantErr: false,
}, {
name: "carlin lower case",
town: "carlin",
want: true,
wantErr: false,
}, {
name: "carlin upper case",
town: "CARLIN",
want: true,
wantErr: false,
}, {
name: "carlin mixed case",
town: "CaRlIn",
want: true,
wantErr: false,
}, {
name: "ab'dendriel lower case",
town: "ab'dendriel",
want: true,
wantErr: false,
}, {
name: "ab'dendriel upper case",
town: "AB'DENDRIEL",
want: true,
wantErr: false,
}, {
name: "ab'dendriel mixed case",
town: "Ab'DeNdRiEl",
want: true,
wantErr: false,
}, {
name: "port hope lower case",
town: "port hope",
want: true,
wantErr: false,
}, {
name: "port hope upper case",
town: "PORT HOPE",
want: true,
wantErr: false,
}, {
name: "port hope mixed case",
town: "PoRt HoPe",
},
"carlin": {
towns: []string{"carlin", "CARLIN", "CaRlIn"},
want: true,
wantErr: false,
}, {
name: "port hope lower case with '+'",
town: "port+hope",
},
"ab'dendriel": {
towns: []string{"ab'dendriel", "AB'DENDRIEL", "Ab'DeNdRiEl"},
want: true,
wantErr: false,
}, {
name: "port hope upper case with '+'",
town: "PORT+HOPE",
},
"port hope": {
towns: []string{"port hope", "PORT HOPE", "PoRt HoPe"},
want: true,
wantErr: false,
}, {
name: "port hope mixed case with '+'",
town: "PoRt+HoPe",
},
"port hope with +": {
towns: []string{"port+hope", "PORT+HOPE", "PoRt+HoPe"},
want: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := TownExists(tt.town)
if (err != nil) != tt.wantErr {
t.Errorf("TownExists() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("TownExists() = %v, want %v", got, tt.want)
}
})

// Iterate over test data and run subtests
for name, data := range testData {
for _, town := range data.towns {
t.Run(fmt.Sprintf("%s (%s)", name, town), func(t *testing.T) {
got, err := TownExists(town)
if (err != nil) != data.wantErr {
t.Errorf("TownExists() error = %v, wantErr %v", err, data.wantErr)
return
}
if got != data.want {
t.Errorf("TownExists() = %v, want %v", got, data.want)
}
})
}
}
}
Loading