wip: turn generation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package game_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"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 TestDestroyProbability(t *testing.T) {
|
||||
probability := game.DestroyProbability(ship.Weapons, 1, ship.Shields, 1, ship.EmptyMass())
|
||||
assert.Equal(t, .5, probability)
|
||||
|
||||
unsinkableShip := ship
|
||||
unsinkableShip.Shields = 55
|
||||
probability = game.DestroyProbability(ship.Weapons, 1, unsinkableShip.Shields, 1, unsinkableShip.EmptyMass())
|
||||
assert.LessOrEqual(t, probability, 0.)
|
||||
|
||||
disruptiveShip := ship
|
||||
disruptiveShip.Weapons = 40
|
||||
probability = game.DestroyProbability(disruptiveShip.Weapons, 1, ship.Shields, 1, ship.EmptyMass())
|
||||
assert.GreaterOrEqual(t, probability, 1.)
|
||||
}
|
||||
|
||||
func TestEffectiveDefence(t *testing.T) {
|
||||
assert.Equal(t, 10., game.EffectiveDefence(ship.Shields, 1, ship.EmptyMass()))
|
||||
|
||||
attackerEffectiveDefence := game.EffectiveDefence(attacker.Shields, 1, attacker.EmptyMass())
|
||||
defenderEffectiveDefence := game.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)
|
||||
}
|
||||
Reference in New Issue
Block a user