diff --git a/test/test_ddp.jl b/test/test_ddp.jl index c9bbb867..36568174 100644 --- a/test/test_ddp.jl +++ b/test/test_ddp.jl @@ -431,6 +431,23 @@ Tests for markov/ddp.jl @test Matrix(_ddp.Q) == _Q end end + + # the unsorted inputs must not be mutated by construction, and + # constructing from the same arrays again must succeed (issue + # #117); fresh inputs per Q format, never passed to a constructor + # before, so that the literal baselines cannot be contaminated + for make_Q in (identity, sparse) + s_in, a_in = [1, 2, 1], [1, 1, 2] + R_in = [0.0, 2.0, 1.0] + Q_in = make_Q([1.0 0.0; 0.0 1.0; 0.5 0.5]) + for _ in 1:2 # reconstruction from the same arrays must succeed + _ddp = DiscreteDP(R_in, Q_in, beta, s_in, a_in) + @test s_in == [1, 2, 1] + @test a_in == [1, 1, 2] + @test R_in == [0.0, 2.0, 1.0] + @test Matrix(Q_in) == [1.0 0.0; 0.0 1.0; 0.5 0.5] + end + end end @testset "num_sa_pairs and form converters" begin