Queue tests

This commit is contained in:
2019-09-16 21:37:34 +03:00
parent 3651af523d
commit 2765c5b4c9
5 changed files with 62 additions and 31 deletions

View File

@ -14,22 +14,15 @@ struct Point
end
abstract class Tile
property cap : Int32 = 0
def initialize(@point : Point)
@cap = 0
@cur = 0
end
def point
@point
end
def cap
@cap
end
def cur
@cur
end
getter point
getter cap
getter cur
def withdraw(value)
if value >= @cur

View File

@ -1,25 +1,25 @@
class App::Queue(T)
struct Item(T)
def initialize(@ts : Int32, @value : T)
class App::Queue
struct Item
def initialize(@ts : Int32, @command : Command)
end
getter ts
getter value
getter command
end
def initialize
@data = [] of Item(T)
@data = [] of Item
end
# Plan finishing of *command* at time *ts*
def push(ts : Int32, value : T)
def push(ts : Int32, value : Command)
@data.push(Item.new(ts, value))
@data.sort! do |a, b|
b.ts <=> a.ts
end
end
def pop(ts : Int32) : Item(T) | Nil
def pop(ts : Int32) : Item | Nil
if @data.size == 0
return nil
end

View File

@ -21,7 +21,7 @@ class World
@ts = 0
@resources = Resources.new
@map = Map.new
@queue = App::CommandQueue.new
@queue = App::Queue.new
end
private def ts
@ -49,8 +49,8 @@ class World
if item.nil?
break
end
command_ts, command = item[:ts], item[:cmd]
@ts = command_ts
command = item.command
@ts = item.ts
command.finish(self)
printf "world : %d : finish `%s`\n", @ts, typeof(command)
end