lib/y_petri/simulation/timed.rb in y_petri-2.4.2 vs lib/y_petri/simulation/timed.rb in y_petri-2.4.3

- old
+ new

@@ -238,11 +238,16 @@ if settings.has? :time, syn!: :time_range then # time range given case settings[:time] when Range then time_range = settings[:time] @initial_time, @target_time = time_range.begin, time_range.end - @time_unit = initial_time.class.one + @time_unit = case initial_time + when Float then 1.0 + when Integer then 1 + else + initial_time.class.one + end else # TODO: When using simulation after some time, I found this behavior # surprising. I wanted to call simulation time: 100, expecting it # to run until 100 (in the range 0..100). Instead, I see that it wants # to run from 100 to infinity. While I understand how important it @@ -259,18 +264,28 @@ # the code until the tests pass. Then, to reintroduce "time" # parameter with the new, more intuitive meaning. Interactive # users can always modify time later (simulation.time = something). # @initial_time = settings[:time] - @time_unit = initial_time.class.one + @time_unit = case initial_time + when Float then 1.0 + when Integer then 1 + else + initial_time.class.one + end @target_time = time_unit * Float::INFINITY end else anything = settings[:step] || settings[:sampling] msg = "The simulation is timed, but the constructor lacks any of the " + "time-related arguments: :time, :step, or :sampling!" fail ArgumentError, msg unless anything - @time_unit = anything.class.one + @time_unit = case anything + when Float then 1.0 + when Integer then 1 + else + anything.class.one + end @initial_time, @target_time = time_unit * 0, time_unit * Float::INFINITY end # Set up a parametrized subclas of the sampler for timed simulation. param_class( { Recorder: Recorder }, with: { simulation: self } ) reset_time!