include("Automaton.jl") using Test @testset "simple simulation tests" begin @testset "test simple integrator (exposeState = false)" begin integrator = (x, u) -> (x+u, x+u) timespan = 1:10 integrator! = Automaton.toInOut(integrator, 0) step_response = Automaton.evolution(integrator!, (1 for _ in timespan)); output = [y for y in step_response]; @test output == [i for i in timespan] end @testset "test simple integrator (exposeState = true)" begin integrator = (x, u) -> (x+u, x+u) timespan = 1:10 integrator! = Automaton.toInOut(integrator, 0; exposeState=true) step_response = Automaton.evolution(integrator!, (1 for _ in timespan)); output = [y for (y, x) in step_response]; @test output == [i for i in timespan] end @testset "test if the exposed state is safe to manipulate" begin delay = (x, u) -> (u, x) # Intentionaly use mutable data structure (array) because # this will allow us to test if it is safe to manipulate the returned # state externaly! delay! = Automaton.toInOut(delay, [0]; exposeState=true) # Advance the automaton y, x = delay!([1]) @test y == [0] @test x == [1] # Try to manipulate state. # This action should not affect the state of the automaton itself. x[1] = 5 # Advance the automaton, again y, x = delay!([2]) @test y == [1] @test x == [2] end end