package battle_test import ( "testing" "github.com/iliadenisov/galaxy/internal/game/battle" "github.com/iliadenisov/galaxy/internal/model/game" "github.com/stretchr/testify/assert" ) var ( attacker = game.ShipType{ ShipTypeReport: game.ShipTypeReport{ Name: "Attacker", Drive: 8, Armament: 1, Weapons: 8, Shields: 8, Cargo: 0, }, } defender = game.ShipType{ ShipTypeReport: game.ShipTypeReport{ Name: "Defender", Drive: 1, Armament: 1, Weapons: 1, Shields: 1, Cargo: 0, }, } ship = game.ShipType{ ShipTypeReport: game.ShipTypeReport{ Name: "Ship", Drive: 10, Armament: 1, Weapons: 10, Shields: 10, Cargo: 0, }, } ) func TestDestructionProbability(t *testing.T) { probability := battle.DestructionProbability(ship.Weapons, 1, ship.Shields, 1, ship.EmptyMass()) assert.Equal(t, .5, probability) undefeatedShip := ship undefeatedShip.Shields = 55 probability = battle.DestructionProbability(ship.Weapons, 1, undefeatedShip.Shields, 1, undefeatedShip.EmptyMass()) assert.LessOrEqual(t, probability, 0.) disruptiveShip := ship disruptiveShip.Weapons = 40 probability = battle.DestructionProbability(disruptiveShip.Weapons, 1, ship.Shields, 1, ship.EmptyMass()) assert.GreaterOrEqual(t, probability, 1.) } func TestEffectiveDefence(t *testing.T) { assert.Equal(t, 10., battle.EffectiveDefence(ship.Shields, 1, ship.EmptyMass())) attackerEffectiveDefence := battle.EffectiveDefence(attacker.Shields, 1, attacker.EmptyMass()) defenderEffectiveDefence := battle.EffectiveDefence(defender.Shields, 1, defender.EmptyMass()) // attacker's effective shields must be 'just' 4 times greater than defender's assert.InDelta(t, defenderEffectiveDefence*4, attackerEffectiveDefence, 0) }