Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminato senza ostacoli #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .besouro/20161116152157833/actions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
FileOpenedAction 1479306118530 MarsRoverTest.java 184 1 1 0
FileOpenedAction 1479306192459 MarsRover.java 1090 2 1 0
FileOpenedAction 1479306248012 MarsRoverException.java 155 0 0 0
RefactoringAction 1479307998998 MarsRover.java ADD String executeCommand(String)/2 METHOD
RefactoringAction 1479308017024 MarsRover.java RENAME executeCommand(String)/2=>void String(String) METHOD
RefactoringAction 1479308024560 MarsRover.java RENAME String(String)=>String forward(String) METHOD
RefactoringAction 1479308026586 MarsRover.java RENAME forward(String)=>String orward(String) METHOD
RefactoringAction 1479308027604 MarsRover.java RENAME orward(String)=>String Forward(String) METHOD
RefactoringAction 1479308643200 MarsRover.java ADD String Forward(String)/2 METHOD
RefactoringAction 1479308644229 MarsRover.java ADD String Forward(String)/3 METHOD
RefactoringAction 1479308649813 MarsRover.java ADD String Forward(String)/4 METHOD
RefactoringAction 1479308670344 MarsRover.java RENAME Forward(String)/4=>String backward(String) METHOD
RefactoringAction 1479308687940 MarsRover.java RENAME Forward(String)/3=>String left(String) METHOD
RefactoringAction 1479308689496 MarsRover.java RENAME left(String)=>String eft(String) METHOD
RefactoringAction 1479308690508 MarsRover.java RENAME eft(String)=>String Left(String) METHOD
RefactoringAction 1479308710526 MarsRover.java RENAME Forward(String)/2=>String right(String) METHOD
RefactoringAction 1479308804609 Car.java ADD Car.java CLASS
FileOpenedAction 1479308804870 Car.java 59 0 0 0
RefactoringAction 1479308828405 Car.java ADD void MarsRover(int, int, String) METHOD
RefactoringAction 1479308831932 Car.java RENAME MarsRover(int, int, String)=>Car(int, int, String) METHOD
RefactoringAction 1479309102449 MarsRover.java ADD int x FIELD
RefactoringAction 1479309105992 MarsRover.java ADD int y FIELD
RefactoringAction 1479309114573 MarsRover.java ADD String obstacles FIELD
RefactoringAction 1479309169357 MarsRover.java ADD MarsRover rover FIELD
RefactoringAction 1479309183181 Car.java RENAME Car(int, int, String)=>Car() METHOD
RefactoringAction 1479309239697 Car.java RENAME Car()=>Car(int, int, String) METHOD
RefactoringAction 1479309314295 Car.java RENAME Car(int, int, String)=>Car() METHOD
RefactoringAction 1479309338932 MarsRover.java ADD Car Car FIELD
RefactoringAction 1479309512143 Car.java ADD int y FIELD
RefactoringAction 1479309535911 Car.java REMOVE y FIELD
RefactoringAction 1479309536915 Car.java ADD int x FIELD
RefactoringAction 1479309541423 Car.java ADD int y FIELD
RefactoringAction 1479309549946 Car.java ADD String facing FIELD
RefactoringAction 1479309664052 MarsRover.java RENAME backward(String)=>String ackward(String) METHOD
RefactoringAction 1479309665073 MarsRover.java RENAME ackward(String)=>String Backward(String) METHOD
RefactoringAction 1479309963708 MarsRover.java RENAME Forward(String)=>Car Forward() METHOD
RefactoringAction 1479309968727 MarsRover.java RENAME Backward(String)=>Car Backward() METHOD
RefactoringAction 1479309973735 MarsRover.java RENAME Left(String)=>String Left() METHOD
RefactoringAction 1479312757291 MarsRover.java RENAME right(String)=>Car ight(String) METHOD
RefactoringAction 1479312758812 MarsRover.java RENAME ight(String)=>Car Right(String) METHOD
RefactoringAction 1479312772331 MarsRover.java RENAME Right(String)=>Car Right() METHOD
RefactoringAction 1479312847202 MarsRoverTest.java ADD void test()/2 METHOD
RefactoringAction 1479312865216 MarsRoverTest.java RENAME test()/2=>void testForward() METHOD
EditAction 1479312932614 Car.java 160 1 3 0
RefactoringAction 1479312939558 MarsRoverTest.java ADD import tdd.training.session1.Car IMPORT
RefactoringAction 1479312989442 MarsRoverTest.java ADD import tdd.training.session1.MarsRover IMPORT
FileOpenedAction 1479313166559 Car.java 160 1 3 0
EditAction 1479313230561 Car.java 167 1 3 0
EditAction 1479313356150 MarsRover.java 2425 6 13 0
UnitTestCaseAction 1479313357426 MarsRoverTest.java FAIL
UnitTestSessionAction 1479313357434 MarsRoverTest FAIL
UnitTestCaseAction 1479313377053 MarsRoverTest.java OK
UnitTestSessionAction 1479313377054 MarsRoverTest OK
UnitTestCaseAction 1479313412695 MarsRoverTest.java OK
UnitTestSessionAction 1479313412696 MarsRoverTest OK
RefactoringAction 1479313426933 MarsRoverTest.java RENAME testForward()=>void testCommand() METHOD
RefactoringAction 1479313431940 MarsRoverTest.java RENAME testCommand()=>void testCommand1() METHOD
RefactoringAction 1479313447467 MarsRoverTest.java ADD void testCommand1()/2 METHOD
RefactoringAction 1479313454477 MarsRoverTest.java REMOVE testCommand1()/2 METHOD
RefactoringAction 1479313458487 MarsRoverTest.java RENAME testCommand1()=>void testForward() METHOD
RefactoringAction 1479313464029 MarsRoverTest.java ADD void testCommand1() METHOD
RefactoringAction 1479313472586 MarsRoverTest.java RENAME testForward()=>void testC() METHOD
RefactoringAction 1479313474095 MarsRoverTest.java RENAME testC()=>void testCommand() METHOD
RefactoringAction 1479313476124 MarsRoverTest.java RENAME testCommand()=>void testCommand1()/2 METHOD
RefactoringAction 1479313481136 MarsRoverTest.java RENAME testCommand1()/2=>void testCommand2() METHOD
RefactoringAction 1479313485158 MarsRoverTest.java ADD void testCommand1()/2 METHOD
RefactoringAction 1479313488178 MarsRoverTest.java RENAME testCommand1()/2=>void testCommand3() METHOD
UnitTestCaseAction 1479313513990 MarsRoverTest.java OK
UnitTestSessionAction 1479313513990 MarsRoverTest OK
RefactoringAction 1479313543266 MarsRoverTest.java ADD void testCommand1()/2 METHOD
RefactoringAction 1479313546795 MarsRoverTest.java RENAME testCommand1()/2=>void testCommand3()/2 METHOD
CompilationAction 1479313579168 MarsRoverTest.java
UnitTestCaseAction 1479313582347 MarsRoverTest.java OK
UnitTestSessionAction 1479313582347 MarsRoverTest OK
RefactoringAction 1479313585478 MarsRoverTest.java RENAME testCommand3()/2=>void testCommand4() METHOD
RefactoringAction 1479313622566 MarsRoverTest.java REMOVE testCommand4() METHOD
UnitTestCaseAction 1479313626107 MarsRoverTest.java OK
UnitTestSessionAction 1479313626107 MarsRoverTest OK
17 changes: 17 additions & 0 deletions .besouro/20161116152157833/besouroEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1479313377054 test-first 4 7258 true
1479313377055 test-first 4 7258 true
1479313377056 test-first 4 7258 true
1479313412696 regression 1 0 true
1479313513990 test-addition 1 87 true
1479313513991 test-addition 1 87 true
1479313513992 test-addition 1 87 true
1479313582347 test-addition 1 39 true
1479313626107 refactoring 1B 40 true
1479313626108 refactoring 1B 40 true
1479313626109 refactoring 3 40 true
1479313626110 refactoring 3 40 true
1479313626111 refactoring 3 40 true
1479313626112 refactoring 2B 40 true
1479313626113 refactoring 2B 40 true
1479313626114 refactoring 3 40 true
1479313626115 regression 1 40 true
Empty file.
5 changes: 5 additions & 0 deletions .besouro/20161116152157833/randomHeuristicEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1479313377054 test-first 4 7258 true
1479313412696 regression 1 0 true
1479313513990 test-addition 1 87 false
1479313582347 test-addition 1 39 false
1479313626107 refactoring 1B 40 false
Empty file.
5 changes: 5 additions & 0 deletions .besouro/20161116152157833/zorroEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1479313377054 test-first 4 7258 true
1479313412696 regression 1 35 true
1479313513990 test-addition 1 101 true
1479313582347 test-addition 1 68 true
1479313626107 refactoring 1B 43 true
13 changes: 13 additions & 0 deletions src/tdd/training/session1/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tdd.training.session1;

public class Car {
public int x, y;
String facing="N";

public Car(){
this.x=0;
this.y=0;
this.facing="N";
}

}
57 changes: 56 additions & 1 deletion src/tdd/training/session1/MarsRover.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
package tdd.training.session1;

public class MarsRover {
static int x;
static int y;
String obstacles;
public MarsRover(int x, int y, String obstacles){
/* x and y represent the size of the grid.
* Obstacles is a String formatted as follows: ?(o1_x,o1_y)(o2_x,o2_y)...(on_x,on_y)? with no white spaces.
*
Example use:
MarsRover rover = new MarsRover(100,100,"?(5,5)(7,8)?") //A 100x100 grid with two obstacles at coordinates (5,5) and (7,8)
*/
x=this.x;
y=this.y;
obstacles=this.obstacles;
}
MarsRover rover = new MarsRover(x,y,obstacles);
Car Car= new Car();


public String executeCommand(String command){

for(int i=0; i<command.length(); i++){
char a = command.charAt(i);
if(a == 'f'){
Forward();
}
if(a == 'b'){
Backward();
}
if(a == 'l'){
Left();
}
if(a == 'r'){
Right();
}
}
/* The command string is composed of "f" (forward), "b" (backward), "l" (left) and "r" (right)
* Example:
* The rover is on a 100x100 grid at location (0, 0) and facing NORTH. The rover is given the commands "ffrff" and should end up at (2, 2) facing East.
Expand All @@ -23,4 +46,36 @@ public String executeCommand(String command){

return null;
}
public Car Forward(){
if(Car.y<=MarsRover.y && Car.facing=="N"){
Car.y++;
}else if(Car.facing=="S" || Car.facing=="E" || Car.facing=="W"){
Car.facing="N";
}
return Car; //torna lo stato del veicolo dopo forward (x,y,facing)
}
public Car Backward(){
if(Car.y>0 && Car.facing=="S"){
Car.y++;
}else if(Car.facing=="N"|| Car.facing=="E" || Car.facing=="W"){
Car.facing="S";
}
return Car; //torna lo stato del veicolo dopo backward (x,y,facing)
}
public Car Left(){
if(Car.facing=="N" || Car.facing=="S" || Car.facing=="E"){
Car.facing="W";
}else if(Car.x>0 && Car.facing=="W"){
Car.x--;
}
return Car; //torna lo stato del veicolo dopo left (x,y,facing)
}
public Car Right(){
if(Car.facing=="N" || Car.facing=="S" || Car.facing=="W"){
Car.facing="W";
}else if(Car.x<MarsRover.x && Car.facing=="E"){
Car.x++;
}
return Car; //torna lo stato del veicolo dopo right (x,y,facing)
}
}
36 changes: 34 additions & 2 deletions src/tdd/training/tests/MarsRoverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,43 @@

import org.junit.Test;

import tdd.training.session1.Car;
import tdd.training.session1.MarsRover;

public class MarsRoverTest {

@Test
public void test() {
fail("Not yet implemented");
//fail("Not yet implemented");
}
public void testCommand1(){
Car Car= new Car();
MarsRover Rover = new MarsRover(3,3,"");
Car.x=1;
Car.y=1;

Rover.executeCommand("fb");

assertEquals(Car.x,1);
}
public void testCommand2(){
Car Car= new Car();
MarsRover Rover = new MarsRover(3,3,"");
Car.x=1;
Car.y=1;

Rover.executeCommand("fbff");

assertEquals(Car.y,2);
}
public void testCommand3(){
Car Car= new Car();
MarsRover Rover = new MarsRover(3,3,"");
Car.x=1;
Car.y=1;

Rover.executeCommand("fbffr");

assertEquals(Car.x,2);
}

}