using Base.Test
@testset "Broadcast and vectorization" begin
@testset "Base.broadcast" begin
    A::Vector{Float64} = 1:5
    # A = [1.0, 2.0, 3.0, 4.0, 5.0]
    B::Array{Float64, 2} = reshape(1:10,(5,2))
    # B = [1.0 6.0; 2.0 7.0; 3.0 8.0; 4.0 9.0; 5.0 10.0]
    C = broadcast(+, A, B)
    # C = [2.0 7.0; 4.0 9.0; 6.0 11.0; 8.0 13.0; 10.0 15.0]
    @test C[1,1] == 2
    @test C[5,2] == 15
end
# ============================================= #
@testset "Base.broadcast!" begin
    X::Vector{Float64} = 1:5
    # A = [1.0, 2.0, 3.0, 4.0, 5.0]
    Y::Array{Float64, 2} = reshape(1:10,(5,2))
    # B = [1.0 6.0; 2.0 7.0; 3.0 8.0; 4.0 9.0; 5.0 10.0]
    broadcast!(+, Y, X, Y)
    # B = [2.0 7.0; 4.0 9.0; 6.0 11.0; 8.0 13.0; 10.0 15.0]
    @test Y[1,1] == 2
    @test Y[5,2] == 15

    X = 1:5
    Y = reshape(1:10, (5,2))
    a::Float64 = 0.5
    broadcast!((x,y)->begin 
        a*x + y
    end, Y, X, Y)

    @test Y[1,1] == 1.5
    @test Y[5,2] == 12.5
end
# ============================================= #
@testset "Dot operator" begin
    # Vectorized dot operator #
    a::Float64 = 0.5
    X::Vector{Float64} = 1:5
    Y::Array{Float64, 2} = reshape(1:10, (5,2))
    Y .= a.*X .+ Y

    @test Y[1,1] == 1.5
    @test Y[5,2] == 12.5
# --------------------------------------------- #
    # Another kind of dot expression #
    X = 1:5
    Y = reshape(1:10, (5,2))
    @. Y = a*X + Y

    @test Y[1,1] == 1.5
    @test Y[5,2] == 12.5
end

end





# --------------------------------------------- #
# ============================================= #
# --------------------------------------------- #
# ============================================= #
# --------------------------------------------- #
# ============================================= #
# --------------------------------------------- #
# ============================================= #
# --------------------------------------------- #
# ============================================= #
# --------------------------------------------- #
