143 lines
3.2 KiB
Go
143 lines
3.2 KiB
Go
package alt_advancement
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"eq2emu/internal/database"
|
|
)
|
|
|
|
// TestSimpleAltAdvancement tests the basic new AltAdvancement functionality
|
|
func TestSimpleAltAdvancement(t *testing.T) {
|
|
db, err := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create test database: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
// Test creating a new alternate advancement
|
|
aa := New(db)
|
|
if aa == nil {
|
|
t.Fatal("New returned nil")
|
|
}
|
|
|
|
if !aa.IsNew() {
|
|
t.Error("New AA should be marked as new")
|
|
}
|
|
|
|
// Test setting values
|
|
aa.SpellID = 1001
|
|
aa.NodeID = 1001
|
|
aa.Name = "Dragon's Strength"
|
|
aa.Group = AA_CLASS
|
|
aa.RankCost = 1
|
|
aa.MaxRank = 5
|
|
|
|
if aa.GetID() != 1001 {
|
|
t.Errorf("Expected GetID() to return 1001, got %d", aa.GetID())
|
|
}
|
|
|
|
// Test validation
|
|
if !aa.IsValid() {
|
|
t.Error("AA should be valid after setting required fields")
|
|
}
|
|
|
|
// Test Clone
|
|
clone := aa.Clone()
|
|
if clone == nil {
|
|
t.Fatal("Clone returned nil")
|
|
}
|
|
|
|
if clone.NodeID != aa.NodeID {
|
|
t.Errorf("Expected clone ID %d, got %d", aa.NodeID, clone.NodeID)
|
|
}
|
|
|
|
if clone.Name != aa.Name {
|
|
t.Errorf("Expected clone name %s, got %s", aa.Name, clone.Name)
|
|
}
|
|
|
|
// Ensure clone is not the same instance
|
|
if clone == aa {
|
|
t.Error("Clone should return a different instance")
|
|
}
|
|
}
|
|
|
|
// TestMasterListWithGeneric tests the master list with generic base
|
|
func TestMasterListWithGeneric(t *testing.T) {
|
|
masterList := NewMasterList()
|
|
|
|
if masterList == nil {
|
|
t.Fatal("NewMasterList returned nil")
|
|
}
|
|
|
|
if masterList.Size() != 0 {
|
|
t.Errorf("Expected size 0, got %d", masterList.Size())
|
|
}
|
|
|
|
// Create an AA (need database for new pattern)
|
|
db, _ := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
|
defer db.Close()
|
|
|
|
aa := New(db)
|
|
aa.SpellID = 1001
|
|
aa.NodeID = 1001
|
|
aa.Name = "Dragon's Strength"
|
|
aa.Group = AA_CLASS
|
|
aa.RankCost = 1
|
|
aa.MaxRank = 5
|
|
|
|
// Test adding
|
|
if !masterList.AddAltAdvancement(aa) {
|
|
t.Error("Should successfully add alternate advancement")
|
|
}
|
|
|
|
if masterList.Size() != 1 {
|
|
t.Errorf("Expected size 1, got %d", masterList.Size())
|
|
}
|
|
|
|
// Test retrieving
|
|
retrieved := masterList.GetAltAdvancement(1001)
|
|
if retrieved == nil {
|
|
t.Error("Should retrieve added alternate advancement")
|
|
}
|
|
|
|
if retrieved.Name != "Dragon's Strength" {
|
|
t.Errorf("Expected name 'Dragon's Strength', got '%s'", retrieved.Name)
|
|
}
|
|
|
|
// Test filtering
|
|
classAAs := masterList.GetAltAdvancementsByGroup(AA_CLASS)
|
|
if len(classAAs) != 1 {
|
|
t.Errorf("Expected 1 AA in Class group, got %d", len(classAAs))
|
|
}
|
|
}
|
|
|
|
// TestAltAdvancementValidation tests validation functionality
|
|
func TestAltAdvancementValidation(t *testing.T) {
|
|
db, _ := database.NewSQLite("file::memory:?mode=memory&cache=shared")
|
|
defer db.Close()
|
|
|
|
// Test valid AA
|
|
validAA := New(db)
|
|
validAA.SpellID = 100
|
|
validAA.NodeID = 100
|
|
validAA.Name = "Test AA"
|
|
validAA.RankCost = 1
|
|
validAA.MaxRank = 5
|
|
|
|
if !validAA.IsValid() {
|
|
t.Error("Valid AA should pass validation")
|
|
}
|
|
|
|
// Test invalid AA - missing name
|
|
invalidAA := New(db)
|
|
invalidAA.SpellID = 100
|
|
invalidAA.NodeID = 100
|
|
invalidAA.RankCost = 1
|
|
invalidAA.MaxRank = 5
|
|
// Name is empty
|
|
|
|
if invalidAA.IsValid() {
|
|
t.Error("Invalid AA (missing name) should fail validation")
|
|
}
|
|
}
|