45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
# Nathan Hinton 2 Oct 2025
|
|
|
|
require './planet'
|
|
|
|
require './player'
|
|
|
|
RSpec.describe Planet do
|
|
let(:seed) { 12345 }
|
|
let(:random) { Random.new(seed) }
|
|
let(:planet) { Planet.new(random) }
|
|
let(:player_1) {Player.new('tester 01') }
|
|
let(:player_2) {Player.new('tester 02') }
|
|
|
|
describe '#initialize' do
|
|
it 'stores the random off' do
|
|
expect(planet.instance_variable_get(:@random)).to eq(random)
|
|
end
|
|
|
|
it 'creates a production rate' do
|
|
expect(planet.instance_variable_get(:@prod_rate)).to eq(Random.new(seed).rand)
|
|
end
|
|
|
|
it 'sets a resource' do
|
|
expect(planet.instance_variable_get(:@resource)).to eq(PLANET_PRODUCTION_RESOURCES[(Random.new(seed).rand * PLANET_PRODUCTION_RESOURCES.length).floor])
|
|
end
|
|
|
|
it 'has a nil owner' do
|
|
expect(planet.instance_variable_get(:@owner)).to eq nil
|
|
end
|
|
end # describe #initialize
|
|
|
|
describe '#change_owner' do
|
|
it 'allows an ownership change when the current owner is nil' do
|
|
expect(planet.change_owner(player_1)).to eq(true)
|
|
expect(planet.instance_variable_get(:@owner)).to eq player_1
|
|
end
|
|
|
|
it 'does not change when already owned' do
|
|
planet.change_owner(player_2)
|
|
expect(planet.change_owner(player_1)).to eq(false)
|
|
expect(planet.instance_variable_get(:@owner)).to eq player_2
|
|
end
|
|
end
|
|
end
|