ZeroEpsilon/spec/engine/gravity/field_spec.cr

21 lines
691 B
Crystal

require "../../../src/engine/gravity/field"
describe Gravity::Field do
earth = Gravity::Body(2).new(mass: 5972200000000000000000000.0, position: Vector[0.0, 0.0])
earth_surface = Vector[6371000.0, 0.0]
it "accelerate arbitrary points" do
field = Gravity::Field(2).new([earth])
field = Gravity::Field(2).new(earth)
field = Gravity::Field(2).new({earth})
earth.acceleration(earth_surface).magnitude.round(2).should eq(9.82)
end
it "allow zero gravity field" do
g = Gravity::Field(2).zero
g.acceleration(earth_surface).magnitude.round(2).should eq(0)
g = Gravity::Field(2).new
g.acceleration(earth_surface).magnitude.round(2).should eq(0)
end
end