Skip to content
Snippets Groups Projects
Commit 4811f4b9 authored by Devon Harstrom's avatar Devon Harstrom
Browse files

forgot to re-add these test i made into the git commits and never realized but...

forgot to re-add these test i made into the git commits and never realized but i went thoguh and ran them and everything works fine. Just wanted to note as well since this is one of the final pushes I did use chatgpt just to figure out how to input something into terminal from code since I couldnt figure out how. Other than that its all my code.
parent f857d4a5
No related branches found
No related tags found
2 merge requests!7merging into main,!6merging all refactors into last branch before main
......@@ -7,7 +7,7 @@
> Used code from Ethan McCorquodale a classmate who gave permission to use this old code
I then refactored it </br>
All refactoring was tested on: </br>
Assignment_1/refactored_code/assignment3GUI - Classmate's/src/refactor_1_test.java
Assignment_1/refactored_code/assignment3GUI - Classmate's/src/refactorTests.java
which tests the world functions to see if the game runs properly
> other testing was done in the GUI outside of code as it is a GUI based coed
......
......@@ -4,7 +4,7 @@ import java.io.InputStream;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
class refactor_1_test {
class refactorTests {
private static World world;
@BeforeEach
......@@ -25,6 +25,7 @@ class refactor_1_test {
void testBoardInitialization() {
String simulatedInput = "Assignment_1/original_code/assignment3GUI - Classmate's/src/data.txt";
// String simulatedInput = "Assignment_1/refactored_code/assignment3GUI - Classmate's/src/attackTest.txt\n";
// note chatgpt helped with the system.in portion as i wasn't sure how to enter into terminal though code
InputStream originalSystemInStream = System.in; // Save the original System.in
ByteArrayInputStream simulatedInputStream = new ByteArrayInputStream(simulatedInput.getBytes());
System.setIn(simulatedInputStream); // Set System.in to the new input stream
......@@ -41,8 +42,20 @@ class refactor_1_test {
@Test
void sortDeadTest(){
// not sure how to test because the comment just says doesn't work as intended??
//but works in gui
String simulatedInput = "Assignment_1/original_code/assignment3GUI - Classmate's/src/data.txt";
// String simulatedInput = "Assignment_1/refactored_code/assignment3GUI - Classmate's/src/attackTest.txt\n";
// note chatgpt helped with the system.in portion as i wasn't sure how to enter into terminal though code
InputStream originalSystemInStream = System.in; // Save the original System.in
ByteArrayInputStream simulatedInputStream = new ByteArrayInputStream(simulatedInput.getBytes());
System.setIn(simulatedInputStream); // Set System.in to the new input stream
world = new World(); // This will call FileInitialization.read() and use the simulated input
System.setIn(originalSystemInStream); // Restore the original System.in
world.sortDead();
assertNull(world.location[world.location.length - 1]);
assertNull(world.location[world.location.length - 2]);
assertNull(world.location[world.location.length - 20]);
System.out.println(world.location[world.location.length - 20]);
}
@Test
......@@ -112,5 +125,39 @@ class refactor_1_test {
}
@Test
void testEntities(){
Entity testElfEntity = new Elf();
Entity testOrcEntity = new Orc();
assertNotNull(testElfEntity, "should not be null");
assertNotNull(testOrcEntity, "should not be null");
assertEquals('E', testElfEntity.getAppearance());
assertEquals('O', testOrcEntity.getAppearance());
assertEquals(7, testElfEntity.getDamage());
assertEquals(3, testOrcEntity.getDamage());
assertEquals(15, testElfEntity.getHitPoints());
assertEquals(10, testOrcEntity.getHitPoints());
}
@Test
void testEntityCounters() {
assertEquals(0, Entity.getElfCounter());
assertEquals(0, Entity.getOrcCounter());
Entity.incrementElfCounter(5);
Entity.incrementOrcCounter(-1);
assertEquals(5, Entity.getElfCounter());
assertEquals(-1, Entity.getOrcCounter());
Entity.setElfCounter(0);
Entity.setOrcCounter(0);
assertEquals(0, Entity.getElfCounter());
assertEquals(0, Entity.getOrcCounter());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment