- TrackTest done Track done
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
###############################################################
|
||||
################# #############
|
||||
############### ###########
|
||||
############### #########
|
||||
############### ################## #########
|
||||
############### #################### #########
|
||||
############## ##################### #########
|
||||
############ ###################### ##########
|
||||
######### ###################### ############
|
||||
######### ###################### ##############
|
||||
######### ##################### ################
|
||||
######### ################# ##################
|
||||
######### ################ ##################
|
||||
########## ################## ###############
|
||||
########### #################### #############
|
||||
########### ####################### ##########
|
||||
########## ########################## #########
|
||||
######### ############################ ########
|
||||
######## ############################# ########
|
||||
####### ############################## ########
|
||||
###### ############################# ########
|
||||
###### ############################ #########
|
||||
###### > a ###########
|
||||
###### > a ##############
|
||||
######## > b #################
|
||||
###############################################################
|
||||
@@ -1,10 +1,7 @@
|
||||
package ch.zhaw.pm2.racetrack;
|
||||
|
||||
import ch.zhaw.pm2.racetrack.given.ConfigSpecification;
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -15,64 +12,166 @@ import java.util.List;
|
||||
public class TrackTest {
|
||||
Track trackObj;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
File file = new File("C:\\Studium\\Semester2\\PM2\\Projekt1\\racetrack\\tracks\\challenge.txt");
|
||||
try {
|
||||
trackObj = new Track(file);
|
||||
@Nested
|
||||
@DisplayName("Positiv Test Cases")
|
||||
class positivClass {
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error in Test compareTrack" + e.getMessage());
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
File file = new File(".\\tracks\\challenge.txt");
|
||||
try {
|
||||
trackObj = new Track(file);
|
||||
|
||||
} catch (Exception | PositionVectorNotValid e) {
|
||||
System.err.println("Error in Test compareTrack" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Create correct amount of Car instance")
|
||||
void checkCars() {
|
||||
Assertions.assertEquals(2, trackObj.getCarCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Create Car instance with correct Symbols / Id")
|
||||
void checkCarId() {
|
||||
Assertions.assertEquals('a', trackObj.getCarId(0));
|
||||
Assertions.assertEquals('b', trackObj.getCarId(1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Check getSpaceTyp")
|
||||
void getSpaceTyp() {
|
||||
Assertions.assertEquals(ConfigSpecification.SpaceType.FINISH_RIGHT, trackObj.getSpaceType(new PositionVector(22, 24)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Find FinishLine")
|
||||
void findFinish() {
|
||||
List<PositionVector> expected = new ArrayList<>();
|
||||
expected.add(new PositionVector(22, 22));
|
||||
expected.add(new PositionVector(22, 23));
|
||||
expected.add(new PositionVector(22, 24));
|
||||
Assertions.assertEquals(expected, trackObj.getFinishLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Converts Trackfile correctly to List<String>")
|
||||
void checkTrack() {
|
||||
Track trackObj;
|
||||
try {
|
||||
trackObj = new Track(new File(".\\tracks\\oval-anticlock-right.txt"));
|
||||
List<String> track = new ArrayList<>();
|
||||
track.add("##################################################");
|
||||
track.add("##################################################");
|
||||
track.add("############## #############");
|
||||
track.add("########## ##########");
|
||||
track.add("####### #######");
|
||||
track.add("###### ################# ######");
|
||||
track.add("##### ################### #####");
|
||||
track.add("##### ################### #####");
|
||||
track.add("###### ################# ######");
|
||||
track.add("####### > a #######");
|
||||
track.add("########## > ##########");
|
||||
track.add("############## > b ##############");
|
||||
track.add("##################################################");
|
||||
track.add("##################################################");
|
||||
Assertions.assertLinesMatch(track, trackObj.getTrack());
|
||||
} catch (FileNotFoundException | InvalidTrackFormatException | PositionVectorNotValid e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Make Car move down on track")
|
||||
void makeCarMoveDown() {
|
||||
PositionVector beforeMove = trackObj.getCarPos(0);
|
||||
trackObj.getCar(0).accelerate(PositionVector.Direction.DOWN);
|
||||
trackObj.moveCar(0);
|
||||
PositionVector afterMove = trackObj.getCarPos(0);
|
||||
Assertions.assertEquals(beforeMove.getY() + 1, afterMove.getY());
|
||||
Assertions.assertEquals(beforeMove.getX(), afterMove.getX());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Make Car move with (0,0) acceleration on track")
|
||||
void makeCarStay() {
|
||||
PositionVector beforeMove = trackObj.getCarPos(0);
|
||||
trackObj.moveCar(0);
|
||||
PositionVector afterMove = trackObj.getCarPos(0);
|
||||
Assertions.assertEquals(beforeMove.getY(), afterMove.getY());
|
||||
Assertions.assertEquals(beforeMove.getX(), afterMove.getX());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Will Car Crash")
|
||||
void willCarCrash() {
|
||||
try {
|
||||
//Car will Crash
|
||||
Assertions.assertTrue(trackObj.willCrashAtPosition(0, new PositionVector(25, 21)));
|
||||
//Car will not Crash and is on track
|
||||
Assertions.assertFalse(trackObj.willCrashAtPosition(0, new PositionVector(7, 22)));
|
||||
//Car will not Crash and is on finishLine
|
||||
Assertions.assertFalse(trackObj.willCrashAtPosition(0, trackObj.getFinishLine().get(0)));
|
||||
} catch (PositionVectorNotValid positionVectorNotValid) {
|
||||
positionVectorNotValid.printStackTrace();
|
||||
Assertions.fail("Test should not throw error");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Make Car Crash")
|
||||
void makeCarCrash() {
|
||||
try {
|
||||
trackObj.carDoesCrash(0, new PositionVector(6, 22));
|
||||
} catch (PositionVectorNotValid positionVectorNotValid) {
|
||||
positionVectorNotValid.printStackTrace();
|
||||
Assertions.fail("Test should not throw exception");
|
||||
}
|
||||
Assertions.assertEquals(Track.CRASH_INDICATOR, trackObj.getTrack().get(22).charAt(6));
|
||||
Assertions.assertTrue(trackObj.getCar(0).isCrashed());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void canReadFile() {
|
||||
File file = new File("C:\\Studium\\Semester2\\PM2\\Projekt1\\racetrack\\tracks\\challenge.txt");
|
||||
Assertions.assertThrows(FileNotFoundException.class,() -> new Track(file));
|
||||
}
|
||||
@Nested
|
||||
@DisplayName("Negative TestCase")
|
||||
class negativeClass {
|
||||
File file;
|
||||
|
||||
/**
|
||||
* Dirty test...
|
||||
*/
|
||||
@Test
|
||||
void printOutTrack() {
|
||||
System.out.println(trackObj);
|
||||
}
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
file = new File(".\\tracks\\challenge.txt");
|
||||
try {
|
||||
trackObj = new Track(file);
|
||||
|
||||
@Test
|
||||
void getSpaceTyp() {
|
||||
Assertions.assertEquals(ConfigSpecification.SpaceType.FINISH_RIGHT,trackObj.getSpaceType(new PositionVector(22,24)));
|
||||
}
|
||||
} catch (Exception | PositionVectorNotValid e) {
|
||||
System.err.println("Error in Test compareTrack" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:
|
||||
@Test
|
||||
void addCarAtInit() {
|
||||
try {
|
||||
trackObj.addCar();
|
||||
} catch (InvalidTrackFormatException e) {
|
||||
e.printStackTrace();
|
||||
@Test
|
||||
@DisplayName("Throw error if File not found")
|
||||
void canReadFile() {
|
||||
file = new File(".\\tracks\\NotExisting.txt");
|
||||
Assertions.assertThrows(FileNotFoundException.class, () -> new Track(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Throw error if File is invalid")
|
||||
void invalidTrackFile() {
|
||||
File testfile = new File(".\\src\\test\\InvalidTracks\\sameCar.txt");
|
||||
Assertions.assertThrows(InvalidTrackFormatException.class, () -> new Track(testfile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Invalid Position Vector used")
|
||||
void invalidPositionVector() {
|
||||
Assertions.assertThrows(PositionVectorNotValid.class, () -> trackObj.willCrashAtPosition(0, new PositionVector(100, 200)));
|
||||
Assertions.assertThrows(PositionVectorNotValid.class, () -> trackObj.carDoesCrash(1,new PositionVector(200,100)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void findFinish() {
|
||||
List<PositionVector> expected = new ArrayList<>();
|
||||
expected.add(new PositionVector(22,22));
|
||||
expected.add(new PositionVector(22,23));
|
||||
expected.add(new PositionVector(22,24));
|
||||
Assertions.assertEquals(expected,trackObj.getFinishLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeTrackObj() {
|
||||
try {
|
||||
Track t1 = new Track(new File("C:\\Studium\\Semester2\\PM2\\Projekt1\\racetrack\\tracks\\challenge.txt"));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidTrackFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user