51 lines
2.1 KiB
Crystal
51 lines
2.1 KiB
Crystal
require "../../src/engine/vessel"
|
|
|
|
describe Vessel do
|
|
it "complete station scenario" do
|
|
body = Gravity::MovingBody(2).new(mass: 1_000_000.0)
|
|
gfield = Gravity::Field(2).zero
|
|
v = Vessel(2).new(name: "Starbird", gravity_body: body, gravity_field: gfield)
|
|
v.stations.keys.includes?(:pilot).should be_true
|
|
|
|
rotation = 0
|
|
acceleration = 0
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 3, group: :rotation) { rotation += 1 }
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: -1, group: :rotation) { rotation += 2 }
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 1, group: :acceleration) { acceleration += 1 }
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 2, group: :acceleration) { acceleration += 2 }
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 0, group: :acceleration) { acceleration += 4 }
|
|
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(3)
|
|
executed = v.stations[:pilot].execute_orders!
|
|
executed.size.should eq(2)
|
|
executed[0].group.should eq(:rotation)
|
|
executed[0].priority.should eq(3)
|
|
executed[1].group.should eq(:acceleration)
|
|
executed[1].priority.should eq(2)
|
|
rotation.should eq(1)
|
|
acceleration.should eq(2)
|
|
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(2)
|
|
executed = v.stations[:pilot].execute_orders!
|
|
executed.size.should eq(2)
|
|
rotation.should eq(3)
|
|
acceleration.should eq(3)
|
|
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(1)
|
|
executed = v.stations[:pilot].execute_orders!
|
|
executed.size.should eq(1)
|
|
rotation.should eq(3)
|
|
acceleration.should eq(7)
|
|
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(0)
|
|
executed = v.stations[:pilot].execute_orders!
|
|
executed.size.should eq(0)
|
|
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 1, group: :acceleration) { acceleration += 1 }
|
|
v.stations[:pilot] << Vessel::Order(2).new(priority: 2, group: :acceleration) { |o| o.station.clear_next!(o) }
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(2)
|
|
executed = v.stations[:pilot].execute_orders!
|
|
v.stations[:pilot].orders[:acceleration].size.should eq(0)
|
|
end
|
|
end
|