Skip to content

Commit

Permalink
HalfMap unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrzak committed Jun 17, 2021
1 parent ef5e762 commit 6f6d66d
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Source/Teilaufgabe 3 - Server/MyServer/bin/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/mapValidationTests/
/halfMapRulesUnitTests/
/sendHalfMapUnitTests/
/validateHalfMapUnitTests/
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package halfMapRulesUnitTests;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import MessagesBase.HalfMap;
import MessagesBase.UniqueGameIdentifier;
import exceptions.InvalidMapException;
import rules.IRules;
import rules.RuleHalfMapCastle;

class HalfMapCastle_tests {

@Test
void HalfMapCastle_TwoCastles_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'G', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapCastle();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapCastle_NoCastle_shouldThrow() {
char[][] nodes = { { 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapCastle();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapCastle_CorrectCastle_shouldNotThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapCastle();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertDoesNotThrow(testRule);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package halfMapRulesUnitTests;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import MessagesBase.HalfMap;
import MessagesBase.UniqueGameIdentifier;
import exceptions.InvalidMapException;
import rules.IRules;
import rules.RuleHalfMapEdges;

class HalfMapEdge_tests {

@Test
void HalfMapEdge_TooMuchWaterNorth_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'w', 'w', 'g', 'g', 'g' }, { 'g', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'w', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapEdges();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapEdge_TooMuchWaterSouth_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'w', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'w', 'w', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapEdges();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapEdge_TooMuchWaterEast_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'w', 'w', 'g', 'g', 'g', 'w', 'w' },
{ 'w', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'w' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapEdges();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapEdge_TooMuchWaterWest_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'w', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapEdges();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapEdge_CorrectEdges_shouldNotThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapEdges();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertDoesNotThrow(testRule);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package halfMapRulesUnitTests;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import MessagesBase.HalfMap;
import MessagesBase.UniqueGameIdentifier;
import exceptions.InvalidMapException;
import rules.IRules;
import rules.RuleHalfMapNoIslands;

class HalfMapIslands_tests {

@Test
void HalfMapCastle_Island_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'w', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'w', 'g', 'w' },
{ 'g', 'g', 'w', 'g', 'g', 'g', 'w', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapNoIslands();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapCastle_OtherIsland_shouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'w', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapNoIslands();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapCastle_NoIsland_shouldNotThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'w', 'w', 'g', 'g', 'g', 'w', 'm' },
{ 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g' }, { 'm', 'w', 'w', 'g', 'g', 'm', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapNoIslands();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertDoesNotThrow(testRule);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package halfMapRulesUnitTests;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import MessagesBase.HalfMap;
import MessagesBase.UniqueGameIdentifier;
import exceptions.InvalidMapException;
import rules.IRules;
import rules.RuleHalfMapDimensions;

class HalfMapRightShape_tests {

char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' } };

@Test
void HalfMapInvalidNumberOfNodes_MissingEntireRow_ShouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapInvalidNumberOfNodes_MissingOneField_ShouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapInvalidNumberOfNodes_OneRowTooMany_ShouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapInvalidNumberOfNodes_OneFieldTooMany_ShouldThrow() {
char[][] nodes = { { 'G', 'w', 'g', 'w', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'w', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapInvalidNumberOfNodes_OneFieldTooManyInOneRowOneTooLittleInOther_ShouldThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'w' }, { 'g', 'm', 'w', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'm', 'g', 'g', 'g', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertThrows(InvalidMapException.class, testRule);
}

@Test
void HalfMapCorrectNumberOfNodes_CorrectMap_ShouldNotThrow() {
char[][] nodes = { { 'G', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' },
{ 'm', 'w', 'w', 'g', 'g', 'g', 'g', 'g' }, { 'g', 'm', 'w', 'g', 'g', 'g', 'm', 'm' } };

HalfMap testMap = Helper.halfMapFromArray(nodes);

IRules testingRule = new RuleHalfMapDimensions();

Executable testRule = () -> {
testingRule.validateNewHalfMap(new UniqueGameIdentifier(), testMap);
};

assertDoesNotThrow(testRule);
}

}
Loading

0 comments on commit 6f6d66d

Please sign in to comment.