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.78 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.77 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.76 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.75 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.74 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.73 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.72 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.71 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.70 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.69 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.68 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.67 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.66 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.65 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.64 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.63 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.62 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.61 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.60 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.59 tracks/julia/exercises/robot-simulator/runtests.jl