# construct graph
const N = 5 # must be bigger than 4
F = Graph(N)
for n in 1:N - 2
    for _ in 1:n
        add_arc!(F, n, n + 1)
        add_arc!(F, n, n + 2)
    end
end

# ==
@test ArcIter(F, :, :) == arcs(F, :, :)
@test length(ArcIter(F, :, :)) == F.na
@test length(arcs(F, :, :)) == F.na

# arcs from
@test length(arcs(F, 1, :)) == 2
for i in 2:N - 2
    @test length(arcs(F, i, :)) == 2 * i
end

# arcs into
@test length(arcs(F, :, 1)) == 0
for i in 2:N - 2
    @test length(arcs(F, :, i)) == 2 * i - 3
end

# getindex and setindex!
for a in arcs(F)
    w = rand(1:5)
    F[a,:flow] = w
    @test F[a,:flow] == w 
end

# random
test_ait = arcs(F, 1, :)
rand_test_ait = rand(test_ait)
@test rand_test_ait == (1, 2, 1) || rand_test_ait == (1, 3, 1)

# has_arc
for a in arcs(F)
    @test has_arc(F, a)
end

# add_arc rem_arc for arc type
while !isempty(arcs(F))
    a = ArcIter(F, :, :)

    recount = 0 
    for n in keys(F.fadj), nbrs in keys(F.fadj[n]), key in keys(F.fadj[n][nbrs])
        recount += 1
    end

    @test recount == F.na

    @test add_arc!(F, a[1]) == a[1].key # nothing happens krn a[1] sudah ada
    @test add_arcs_from!(F, a[2:3]) == [a[i].key for i in 2:3] # nothing happens arc[2:3]
    @test rem_arcs_from!(F, a[1:3]) == length(1:3) # removed arcnya
    @test !rem_arc!(F, a[1]) # gaada sisanya
end

# source target key
@test source(Arc(1, 2, 1)) == 1
@test target(Arc(1, 2, 1)) == 2
@test key(Arc(1, 2, 1)) == 1

# ==
@test !has_arc(F, Arc(1, 2, 1))
@test Arc(1, 2, 1) == Arc((1, 2, 1))
add_arcs_from!(F,[(1, 2),(1, 3),(3, 1)])
@test F[1,2,1] == Dictionary()
@test (F[1,2,1,:flow] = 1) == 1
@test (F[1,2,3,:flow] = 2) == 2
@test collect(arcs(F, 1, 2)) == [Arc(1, 2, 1)]