Add small world test

This commit is contained in:
Anton Vakhrushev 2019-10-03 16:32:01 +03:00
parent 2df6b2f3ee
commit 6404a6e519
5 changed files with 18 additions and 5 deletions

View File

@ -24,5 +24,5 @@ format:
.PHONY: spec .PHONY: spec
spec: format spec: format
./crystal spec --warnings all --error-on-warnings ./crystal spec --no-debug --warnings all --error-on-warnings

View File

@ -1,4 +1,4 @@
require "spec" require "./spec_helper"
require "./../src/map" require "./../src/map"
require "./../src/queue" require "./../src/queue"

View File

@ -1,4 +1,4 @@
require "spec" require "./spec_helper"
require "./../src/queue" require "./../src/queue"
require "./../src/command" require "./../src/command"

13
spec/world_spec.cr Normal file
View File

@ -0,0 +1,13 @@
require "./spec_helper"
require "../src/world"
describe "World" do
it "should build crystal harvester" do
world = World.new
point = Point.new(2, 3)
cmd = BuildCrystalHarvesterCommand.new(point)
world.push(cmd)
world.run(100)
world.map.get(point).has_role(TileRole::CrystalHarvester)
end
end

View File

@ -1,3 +1,5 @@
require "./resources"
class World class World
property ts : Int32 property ts : Int32
@ -15,7 +17,6 @@ class World
def push(command : Command) def push(command : Command)
dur = command.start(self) dur = command.start(self)
done_at = @ts + dur done_at = @ts + dur
printf "world : %d : plan `%s` at %d\n", @ts, typeof(command), done_at
@tasks.push(done_at, command) @tasks.push(done_at, command)
end end
@ -28,7 +29,6 @@ class World
command = item.command command = item.command
@ts = item.ts @ts = item.ts
command.finish(self) command.finish(self)
printf "world : %d : finish `%s`\n", @ts, typeof(command)
end end
end end
end end