Cleaning up and writing tests

This commit is contained in:
2025-10-02 21:45:52 -06:00
parent ed3cd08130
commit 279658f3e5
17 changed files with 584 additions and 56 deletions
+44
View File
@@ -0,0 +1,44 @@
# 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