mirror of
https://github.com/logos-storage/swarmsim.git
synced 2026-05-03 17:13:08 +00:00
minor refactor and simplifications to tests
This commit is contained in:
parent
1f84bfe8bd
commit
494a6c6fa1
@ -4,8 +4,9 @@ func `<`*(self: SchedulableEvent, other: SchedulableEvent): bool =
|
|||||||
return self.time < other.time
|
return self.time < other.time
|
||||||
|
|
||||||
method atScheduledTime*(self: SchedulableEvent, engine: EventDrivenEngine): void {.base.} =
|
method atScheduledTime*(self: SchedulableEvent, engine: EventDrivenEngine): void {.base.} =
|
||||||
## Callback invoked by the event engine indicating that this event is due for execution.
|
## Callback invoked by the event engine indicating that this event is due for execution. By
|
||||||
|
## default, it does nothing.
|
||||||
##
|
##
|
||||||
quit "unimplemented"
|
discard
|
||||||
|
|
||||||
export SchedulableEvent
|
export SchedulableEvent
|
||||||
|
|||||||
@ -7,19 +7,12 @@ import std/algorithm
|
|||||||
import pkg/swarmsim/schedulableevent
|
import pkg/swarmsim/schedulableevent
|
||||||
import pkg/swarmsim/eventdrivenengine
|
import pkg/swarmsim/eventdrivenengine
|
||||||
|
|
||||||
type
|
|
||||||
SimpleSchedulable = ref object of SchedulableEvent
|
|
||||||
scheduledAt: uint64
|
|
||||||
|
|
||||||
method atScheduledTime(schedulable: SimpleSchedulable, engine: EventDrivenEngine) =
|
|
||||||
schedulable.scheduledAt = engine.current_time
|
|
||||||
|
|
||||||
suite "event driven engine tests":
|
suite "event driven engine tests":
|
||||||
|
|
||||||
test "should run schedulables at the right time":
|
test "should run schedulables at the right time":
|
||||||
|
|
||||||
let times = @[1, 10, 5].map(time => uint64(time))
|
let times = @[1, 10, 5].map(time => uint64(time))
|
||||||
let schedulables = times.map(time => SimpleSchedulable(time: time))
|
let schedulables = times.map(time => SchedulableEvent(time: time))
|
||||||
|
|
||||||
let engine = EventDrivenEngine()
|
let engine = EventDrivenEngine()
|
||||||
|
|
||||||
@ -27,9 +20,6 @@ suite "event driven engine tests":
|
|||||||
|
|
||||||
for time in times.sorted:
|
for time in times.sorted:
|
||||||
let result = engine.nextStep().get()
|
let result = engine.nextStep().get()
|
||||||
check(result.time == time)
|
check(result.time == engine.current_time)
|
||||||
|
|
||||||
check(engine.nextStep().isNone)
|
check(engine.nextStep().isNone)
|
||||||
|
|
||||||
for schedulable in schedulables:
|
|
||||||
check(schedulable.scheduledAt == schedulable.time)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user