ZeroEpsilon/spec/frequency_engine_spec.cr

24 lines
561 B
Crystal

require "spec"
require "../src/frequency_loop"
describe FrequencyLoop do
it "testes basic looping" do
fl = FrequencyLoop.new(Time::Span.new(nanoseconds: 1_000))
size = 5
i = 0
t0 = Time.utc
fl.loop(max_tick: size) { i += 1 }
t1 = Time.utc
i.should eq(size)
full_span = t1 - t0
# puts "full_span=#{full_span}"
# puts "10nano=#{Time::Span.new(nanoseconds: size * 1_000)}"
# puts "sleep=#{fl.sleep}"
# puts "span=#{fl.span}"
((t1 - t0) > Time::Span.new(nanoseconds: size * 1_000)).should be_true
end
end