Commit ad072c34 authored by Stefanie Hasler's avatar Stefanie Hasler

working

parent f370e7b0
import { expect } from 'chai'
describe('Fibonacci', () => {
})
\ No newline at end of file
import {expect} from 'chai'
class MarsRover {
x: number = 0
y: number = 0
dir: 'N' | 'E' | 'S' | 'W' = 'N'
public pos() {
return `${this.x},${this.y},${this.dir}`
}
forward(): MarsRover {
switch(this.dir) {
case 'E':
this.x++
break
case 'S':
this.y --
break
case 'W':
this.x--
break
default:
this.y++
}
return this
}
right(): MarsRover {
switch (this.dir) {
case 'N':
this.dir = 'E'
break
case 'E':
this.dir = 'S'
break
case 'S':
this.dir = 'W'
break
case 'W':
this.dir = 'N'
}
return this
}
left(): MarsRover {
switch(this.dir) {
case 'N':
this.dir = 'W'
break
case 'E':
this.dir = 'N'
break
case 'S':
this.dir = 'E'
break
case 'W':
this.dir = 'S'
}
return this
}
}
describe("MarsRover", () => {
it('should output starting position', () => {
expect(new MarsRover().pos()).to.equal('0,0,N')
})
it('should move forward', () => {
expect(new MarsRover().forward().pos()).to.equal('0,1,N')
})
it('should turn right', () => {
expect(new MarsRover().right().pos()).to.equal('0,0,E')
})
it('should turn right twice in a row, then point south', () => {
expect(new MarsRover().right().right().pos()).to.equal('0,0,S')
})
it('should turn right three times, then point west', () => {
expect(new MarsRover().right().right().right().pos()).to.equal('0,0,W')
})
it('should turn right four times, then point north', () => {
expect(new MarsRover().right().right().right().right().pos()).to.equal('0,0,N')
})
it('should turn right, move forward, and have moved east', () => {
expect(new MarsRover().right().forward().pos()).to.equal('1,0,E')
})
it('should turn right twice, move forward, and have moved south', () => {
expect(new MarsRover().right().right().forward().pos()).to.equal('0,-1,S')
})
it('should move west', () => {
expect(new MarsRover().right().right().right().forward().pos()).to.equal('-1,0,W')
})
it('should turn left', () => {
expect(new MarsRover().left().pos()).to.equal('0,0,W')
})
})
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment