package game import ( "testing" ) func TestParseIntAttack(t *testing.T) { a := parseAttack(uint64(1)) if a.MaxRange() != 1 { t.Fatal("unexpected max range (1):", a.MaxRange()) } if a.DamageInRange(1) != 1 { t.Fatal("unexpected damage in range 1 (1):", a.DamageInRange(1)) } } func TestParseStringAttack(t *testing.T) { a := parseAttack("1") if a.MaxRange() != 1 { t.Fatal("unexpected max range (1):", a.MaxRange()) } if a.DamageInRange(1) != 1 { t.Fatal("unexpected damage in range 1 (1):", a.DamageInRange(1)) } if a.DamageInRange(2) != 0 { t.Fatal("unexpected damage in range 2 (0):", a.DamageInRange(2)) } } func TestParseRangedAttack(t *testing.T) { a := parseAttack("1 range 2") if a.MaxRange() != 2 { t.Fatal("unexpected max range (2):", a.MaxRange()) } if a.DamageInRange(1) != 1 { t.Fatal("unexpected damage in range 1 (1):", a.DamageInRange(1)) } if a.DamageInRange(2) != 1 { t.Fatal("unexpected damage in range 2 (1):", a.DamageInRange(2)) } if a.DamageInRange(3) != 0 { t.Fatal("unexpected damage in range 3 (0):", a.DamageInRange(3)) } } func TestAttackString(t *testing.T) { aStr := "2 range 3" a := parseAttack(aStr) if a.String() != aStr { t.Fatal("unexpected attack string:", a.String()) } } func TestAttackCopy(t *testing.T) { aStr := "2 range 3" a := parseAttack(aStr) c := a.Copy() c.Extend(1) if a.MaxRange() != 3 { t.Fatal("changed max range") } c.attacks[0] = 1 if a.attacks[0] != 2 { t.Fatal("changed attack in range 0") } } func TestPikeAttack(t *testing.T) { a := parseAttack("1") a.flexAttack = pikeAttack() o := &Tile{Position: Position{0, 0}} u := NewUnit(NewCard("base/cavalry"), o, NewMockPlayer()) enterTile(u, o) tile := &Tile{Position: Position{1, 2}} enterTile(NewUnitFromPath("base/cavalry", tile, NewMockPlayer()), tile) house := &Tile{Position: Position{2, 1}, Type: TileTypes.House, Raw: "house"} enterTile(NewUnitFromPath("base/cavalry", house, NewMockPlayer()), house) // This test is crooked because the attack of the attacking unit is checked in flexAttack and not a. d, ok := a.DamageForTile(u, tile) if !ok { t.Fatal("cavalry not in range for pike attack") } if d != u.Attack.DamageInRange(u.Attack.MaxRange()) { t.Fatal("unexpected damage: amount", d) } d, ok = a.DamageForTile(u, house) if ok || d != 0 { t.Fatal("protected cavalry in range for pike attack") } }