space_agent.jl 2.84 KB
Newer Older
Victor's avatar
Victor committed
1
using LightGraphs
2
3
4
using Test
using Revise,ABMEv

Victor's avatar
Victor committed
5
##### SPACES #####
Victor's avatar
Victor committed
6
7
mysegment = DiscreteSegment(1,10)
mygraph = GraphSpace(SimpleGraph(10,10))
8
9
real2d = RealSpace{2,Float64}()
myline = RealSpace{1,Float16}()
Victor's avatar
Victor committed
10
mydiscreteline = NaturalSpace{1,Int8}()
11
12
13
mycontinuoussegment = ContinuousSegment(-1.,1.)
myspace = (mysegment,mygraph,myline)
myspace2 = (mysegment,mycontinuoussegment,real2d)
Victor's avatar
Victor committed
14

15
16
17
18
19
20
21
22
23
@testset "Space properties" begin
    # checking essential properties of spaces
    @test isfinite(mysegment)  true
    @test isfinite(mygraph)  true
    @test isfinite(myline)  false
    @test ndims(real2d)  2
    @test isfinite(mycontinuoussegment)  true
    @test typeof(myspace) <: AbstractSpacesTuple
    @test eltype(myspace2) == Tuple{Int64,Float64,Tuple{Float64,Float64}}
24

25
    # increment on infinite spaces
Victor's avatar
Victor committed
26
27
28
    @test ABMEv.get_inc(0.,myline)  (0.)
    @test ABMEv.get_inc(0.,mydiscreteline)  (0.)
    @test !(ABMEv.get_inc(1.,myline)  0.)
29
    @test !(get_inc(1,1.,myline)  0.)
Victor's avatar
Victor committed
30
31
    @test !(get_inc(1,1.,mydiscreteline)  0.)

32

Victor's avatar
Victor committed
33
    @test typeof(ABMEv.get_inc([1.,0.],real2d)) == Tuple{Float64,Float64}
34
    @test typeof(get_inc([1.,0.],[1.,0.],real2d)) == Tuple{Float64,Float64}
Victor's avatar
Victor committed
35
36
    @test typeof(ABMEv.get_inc([1.],real2d)) == Tuple{Float64,Float64}
    @test typeof(ABMEv.get_inc(1.,real2d)) == Tuple{Float64,Float64}
37
38
    # ABMEv._get_inc([1.],real2d)
    # ABMEv.initpos(myspace2)
39

Victor's avatar
Victor committed
40

41
42
43
44
45
46
47
48
49
50
51
    # increment on finite spaces
    # checking if reflection works
    @testset "Reflection" begin
        @test mysegment.s - eps() < get_inc(5.,100.,mysegment) + 5. < mysegment.e + eps()
        @test mycontinuoussegment.s < get_inc(0.,100.,mycontinuoussegment) < mycontinuoussegment.e
        mysegment2 = DiscreteSegment(-1,1)
        @test ABMEv._reflect1D(0.,2.0,mysegment2)  .0
        @test ABMEv._reflect1D(0.,-2.0,mysegment2)  .0
        @test ABMEv._reflect1D(0.,4.0,mysegment2)  .0
        @test ABMEv._reflect1D(0.,1.1,mysegment2)  1 - .1
    end
52

53
54
55
    #checking if graph works
    @test prod([get_inc(1,10,mygraph) + 1  vertices(mygraph.g) for i in 1:30])
end
Victor's avatar
Victor committed
56

57
##### AGENTS #######
Victor's avatar
Victor committed
58
59
60
a1 = Agent(myspace)
a2 = Agent(myspace,ancestors = true)
a3 = Agent(myspace,(1,1,1.))
61
62
a4 = Agent(myspace2,(1,1,(1.,1)),rates=true)
a5 = Agent(myspace2,ancestors=true)
Victor's avatar
Victor committed
63

64
65
66
67
68
69
@testset "Agent properties" begin
    # basic test
    @test typeof(a1) <: AbstractAgent
    @test eltype(a1) == eltype(myspace)
    @test eltype(a5) == eltype(myspace2)
    @test typeof(a1) <: AbstractAgent
Victor's avatar
Victor committed
70

71
72
73
74
75
76
77
78
79
    # increment test
    p_myspace = Dict("D"=>[1,1,1],"mu" =>[1,1,1] )
    p_myspace2 = Dict("D"=>[1,1,1],"mu" =>[1,1,1])
    old_a1 = copy(a1)
    @test !prod((get_x(old_a1) . get_x(increment_x!(a1,myspace,p_myspace,0.))))
    @test nancestors(increment_x!(a2,myspace,p_myspace,2.)) > 1
    @test !isnothing(increment_x!(a4,myspace2,p_myspace2,2.))
    @test !isnothing(increment_x!(a5,myspace2,p_myspace2,2.))
end