Sha256: aa4cc0d7b975664b005d1e1dab2f7bb0e8a11cd03239a8a00e3fe28897d65e35

Contents?: true

Size: 1.77 KB

Versions: 141

Compression:

Stored size: 1.77 KB

Contents

using Base.Test

include("robot-simulator.jl")

@testset "constructor" begin
    r = Robot((0, 0), NORTH)
    @test position(r) == Point(0, 0)
    @test heading(r) == NORTH

    r = Robot((-1, -1), SOUTH)
    @test position(r) == Point{Int}(-1, -1)
    @test heading(r) == SOUTH
end

@testset "rotate +π/2" begin
    r = Robot((0, 0), NORTH)
    turn_right!(r)
    @test position(r) == Point(0, 0)
    @test heading(r) == EAST
    turn_right!(r)
    @test heading(r) == SOUTH
    turn_right!(r)
    @test heading(r) == WEST
    turn_right!(r)
    @test heading(r) == NORTH
end

@testset "rotate -π/2" begin
    r = Robot((0, 0), NORTH)
    turn_left!(r)
    @test position(r) == Point(0, 0)
    @test heading(r) == WEST
    turn_left!(r)
    @test heading(r) == SOUTH
    turn_left!(r)
    @test heading(r) == EAST
    turn_left!(r)
    @test heading(r) == NORTH
end

@testset "advance" begin
    r = Robot((0, 0), NORTH)
    advance!(r)
    @test heading(r) == NORTH
    @test position(r) == Point(0, 1)

    @test position(advance!(Robot((0, 0), SOUTH))) == Point(0, -1)
    @test position(advance!(Robot((0, 0), EAST))) == Point(1, 0)
    @test position(advance!(Robot((0, 0), WEST))) == Point(-1, 0)
end

@testset "instructions" begin
    @testset "move west and north" begin
        r = Robot((0, 0), NORTH)
        move!(r, "LAAARALA")
        @test position(r) == Point(-4, 1)
        @test heading(r) == WEST
    end

    @testset "move west and south" begin
        r = Robot((2, -7), EAST)
        move!(r, "RRAAAAALA")
        @test position(r) == Point(-3, -8)
        @test heading(r) == SOUTH
    end

    @testset "move east and north" begin
        r = Robot((8, 4), SOUTH)
        move!(r, "LAAARRRALLLL")
        @test position(r) == Point(11, 5)
        @test heading(r) == NORTH
    end
end

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.57 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.56 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.55 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.54 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.53 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.52 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.51 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.50 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.49 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.48 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.47 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.46 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.45 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.44 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.43 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.42 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.41 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.40 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.39 tracks/julia/exercises/robot-simulator/runtests.jl