using Test
using Forecast
import Forecast: fvar

@testset "forecast_ar" begin

    Φ,Σ2,n = .991,1.,10
    @test fvar(Φ,Σ2,n) ≈ [1.0, 1.982081, 2.946564090561, 3.8937646086222375, 4.823992240600336, 5.737551123641018, 6.634739945056495, 7.515852039981027, 8.381175487276607, 9.230993203720098]

    Φ,Σ,n = [1],1,10
    @test fvar(Φ,Σ,n) == [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]

    Φ,Σ2,n = [.1,.2,.3,.4],1.,10
    @test fvar(Φ,Σ2,n) ≈ [1.0, 1.3, 1.3900000000000001, 1.4170000000000003, 1.4251, 1.42753, 1.4282590000000002, 1.4284777000000002, 1.4285433100000002, 1.4285629930000001] 

    Φ,Σ2,n = [.1 .2;.3 .4],[1. 0.; 0. 1.],10
    @test fvar(Φ,Σ2,n) ≈ [1.0 1.0; 1.05 1.25; 1.0649 1.3209; 1.069185 1.341385; 1.07042201 1.34729681; 1.0707790225 1.3490030505; 1.070882061449 1.3494954953290001; 1.07091179993665 1.34963762183705; 1.07092038288254 1.3496786415463762; 1.0709228600414522 1.3496904804114789]
    
    Φ,Σ2,n = reshape([[.1 .2; .3 .4] [.5 .6; .7 .8]],2,2,2),[.9 .10; .10 .9],10
    @test fvar(Φ,Σ2,n) ≈ [0.9 0.9; 1.896 3.3360000000000003; 5.307360000000001 11.574240000000001; 16.897152000000002 39.571737600000006; 56.28080870400001 134.71025894400003; 190.11105110016 458.00206718976006; 644.8818211024897 1556.5853271158787; 2190.2459254584123 5289.699343417738; 7441.573347348584 17975.25606597047; 25286.196251506655 61082.256992946226]
        
    # ar(Φ,n)
    Φ,n = .5,n
    Φ,Φ0,x0,n = .1,.2,.3,10
    xar = ar(arsim(Φ,Φ0,x0,n),1)
    fxar = forecast(xar,10)
    @test size(fxar.mean,1) == 10

end
