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.119 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.118 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.117 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.116 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.115 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.114 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.113 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.111 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.110 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.109 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.108 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.107 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.106 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.105 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.104 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.103 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.102 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.101 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.100 tracks/julia/exercises/robot-simulator/runtests.jl
trackler-2.2.1.99 tracks/julia/exercises/robot-simulator/runtests.jl