test/simulation_test.rb in y_petri-2.1.3 vs test/simulation_test.rb in y_petri-2.1.6
- old
+ new
@@ -1,9 +1,9 @@
#! /usr/bin/ruby
# encoding: utf-8
-require 'minitest/spec'
+gem 'minitest', '=4.7.4'
require 'minitest/autorun'
require_relative '../lib/y_petri' # tested component itself
# require 'y_petri'
# require 'sy'
@@ -225,12 +225,13 @@
before do
@sim = @net.simulation sampling: 1
end
it "should behave" do
- @sim.recording.must_be_kind_of YPetri::Net::State::Features::Dataset
- @sim.recording.must_equal @net.State.marking.new_dataset.update( 0.0 => [1, 2] )
+ @sim.recording.must_be_kind_of YPetri::Net::DataSet
+ @sim.recording
+ .must_equal @net.State.marking.new_dataset.update( 0.0 => [1, 2] )
@sim.recording.must_equal( { 0.0 => [1, 2] } )
@sim.step! 1
@sim.recording.must_equal( { 0.0 => [1, 2], 1.0 => [2, 1] } )
end
end
@@ -250,11 +251,11 @@
end # transition representation aspects
end
end
-describe YPetri::Simulation do
+describe "timeless simulation" do
before do
self.class.class_exec { include YPetri }
U = Place m!: 2.5
V = Place m!: 2.5
Uplus = Transition codomain: :U do 1 end # s transition
@@ -263,42 +264,46 @@
new_simulation ssc: :Timeless
5.times do simulation.step! end
end
it "should behave" do
- simulation.tap do |s|
- assert ! s.timed?
- s.core.must_be_kind_of YPetri::Core::Timeless::PseudoEuler
- s.recording.size.must_equal 6
- s.recording.events.must_equal [0, 1, 2, 3, 4, 5]
- s.recording.reconstruct( event: 2 ).pm.must_equal( { U: 2.5, V: 4.5 } )
- s.recording.marking.slice( 2..4 ).series
- .must_equal [[2.5, 2.5, 2.5], [4.5, 5.5, 6.5]]
- s.recording.marking( slice: 2..4 )
- .must_equal( { 2 => [2.5, 4.5],
- 3 => [2.5, 5.5],
- 4 => [2.5, 6.5] } )
- s.recording.firing_series( slice: 1..2 )
- .must_equal [[1, 1]]
- s.recording.firing_series( transitions: [:U2V] )
- .must_equal [[1, 1, 1, 1, 1, 1]]
- s.recording.delta_series( places: [:U], transitions: [:Uplus] )
- .must_equal [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
- tmp = s.recording.features( marking: [:U], firing: [:U2V] )
- tmp.delete( :features )
- .must_equal( { marking: [:U], firing: [:U2V],
- delta: { places: [], transitions: [] } } )
- tmp.must_equal( { 0 => [2.5, 1], 1 => [2.5, 1], 2 => [2.5, 1],
- 3 => [2.5, 1], 4 => [2.5, 1], 5 => [2.5, 1] } )
- end
+ s = simulation
+ assert ! s.timed?
+ s.core.must_be_kind_of YPetri::Core::Timeless::PseudoEuler
+ ds = s.recording
+ ds.size.must_equal 6
+ ds.events.must_equal [0, 1, 2, 3, 4, 5]
+ ds.interpolate( 1 )
+ .must_equal [2.5, 3.5]
+ ds.interpolate( 2 )
+ .must_equal [2.5, 4.5]
+ -> { ds.interpolate( 1.5 ) }.must_raise TypeError
+ ds.reconstruct( event: 2 )
+ .pm.must_equal( { U: 2.5, V: 4.5 } )
+ ds.marking.slice( 2..4 ).series
+ .must_equal [[2.5, 2.5, 2.5], [4.5, 5.5, 6.5]]
+ ds.marking.slice( 2..4 )
+ .must_equal( { 2 => [2.5, 4.5],
+ 3 => [2.5, 5.5],
+ 4 => [2.5, 6.5] } )
+ ds.firing.slice( 1..2 ).series
+ .must_equal [[1, 1]]
+ ds.series( firing: [:U2V] )
+ .must_equal [[1, 1, 1, 1, 1, 1]]
+ ds.delta( [:U], transitions: [:Uplus] ).series
+ .must_equal [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]
+ tmp = ds.reduce_features( marking: [:U], firing: [:U2V] )
+ tmp.features
+ .must_equal( ds.net.State.features marking: [:U], firing: [:U2V] )
+ tmp.must_equal( { 0 => [2.5, 1], 1 => [2.5, 1], 2 => [2.5, 1],
+ 3 => [2.5, 1], 4 => [2.5, 1], 5 => [2.5, 1] } )
end
end
-describe YPetri::Simulation::Timed do
+describe "timed simulation" do
before do
- skip
self.class.class_exec { include YPetri }
A = Place m!: 0.5
B = Place m!: 0.5
A_pump = T s: { A: -1 } do 0.005 end
B_decay = Transition s: { B: -1 }, rate: 0.05
@@ -337,18 +342,13 @@
0.3, 0.275, 0.25, 0.225, 0.2 ] ]
s.recording.firing.series
.must_equal []
s.recording.firing
.must_equal( [*0..12].map { |n| n * 5.0 } >> [[]] * 13 )
- # It is obvious why this fails: Given delta feature is not in the
- # recording. It has to be generated, and since the net is timed,
- # it also requires Δt to be generated.
-
- # I'll comment it out for a while to see what the plot is doing.
-=begin
- s.recording.delta( [:A], transitions: [:A_pump] )
+ s.recording
+ .delta( [:A], transitions: [:A_pump], delta_time: 0.1 )
+ .series
.must_equal [ [ -0.0005 ] * 13 ]
-=end
plot_state
sleep 5
end
end
end