Created
February 16, 2016 13:19
-
-
Save real34/1db38dd26f0e357343f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "rx-rover", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "babel-node test.js | faucet", | |
"test_debug": "babel-node test.js" | |
}, | |
"author": "", | |
"license": "ISC", | |
"babel": { | |
"presets": [ | |
"es2015" | |
] | |
}, | |
"dependencies": { | |
"babel-cli": "^6.4.5", | |
"rx": "^4.0.7", | |
"tape": "^4.4.0" | |
}, | |
"devDependencies": { | |
"babel-preset-es2015": "^6.3.13", | |
"faucet": "0.0.1" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tape from 'tape' | |
import {Observable} from 'rx' | |
tape('position initiale', t => { | |
var x= 0, y = 0, o = 'N'; | |
var marsRover = {x, y , o}; | |
const SUT = Observable.of(marsRover) | |
SUT | |
.tap(valeur => t.deepEqual(valeur, marsRover)) | |
.subscribe(() => t.end()) | |
}) | |
tape('nouvelle position', t => { | |
var marsRover= new MarsRover(0,0,'N'); | |
const SUT = Observable.of(marsRover) | |
const commands = Observable.from(['f']) | |
commands | |
.map(valeur => { | |
marsRover.move(valeur); | |
return marsRover; | |
}) | |
.tap( valeur => | |
t.deepEqual(valeur, new MarsRover(0,1,'N')) | |
) | |
.subscribe(() => t.end()) | |
}) | |
tape('nouvelle position', t => { | |
var marsRover= new MarsRover(0,0,'N'); | |
const SUT = Observable.of(marsRover) | |
const commands = Observable.from(['b']) | |
commands | |
.map(valeur => { | |
marsRover.move(valeur); | |
return marsRover; | |
}) | |
.tap( valeur => | |
t.deepEqual(valeur, new MarsRover(0,-1,'N')) | |
) | |
.subscribe(() => t.end()) | |
}) | |
function MarsRover(x,y,o){ | |
this.x=x; | |
this.y=y; | |
this.o=o; | |
} | |
MarsRover.prototype.move =function(direction){ | |
var directions = {'N':{x:0,y:1},'S':{x:0,y:-1},'E':{x:1,y:0},'W':{x:-1,y:0}}; | |
if(direction=='f'){ | |
this.x+=directions[this.o].x; | |
this.y+=directions[this.o].y; | |
}else{ | |
this.x-=directions[this.o].x; | |
this.y-=directions[this.o].y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment