Commit 131f7613 authored by Yuhan Chen's avatar Yuhan Chen
Browse files

Refactored and Tested

parent 96ac27f4
......@@ -41,6 +41,8 @@ public class DemoRuleTwo {
public static Stop stopObj = new Stop(280,200);
public static ArrayList<Wall> wallObjs = new ArrayList<Wall>(20);
public DemoRuleTwo() {}
//Generate Rule.Wall objects
public static void setWallObjs(ArrayList<Wall> wallObjs) {
for (int i = 0; i < 800; i += 40) {
......
package Rule;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
class DemoRuleOneTest {
private static Wall wallTest = new Wall(0,0);
private static Rock rockTest = new Rock(40,80);
private static Baba babaTest = new Baba(80,80);
private static Is isTest = new Is(80,40);
private static Win winObj = new Win(80,120 );
@Test
void atObjectLocation() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(wallTest);
assertEquals(DemoRuleOne.babaObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.babaObj.getY(), rtnObj.getY());
}
@Test
void nearObjectRight() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(babaTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectLeft() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(rockTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectUp() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(isTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectDown() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(winObj);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
}
\ No newline at end of file
package Rule;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class DemoRuleThreeTest {
private static Wall wallTest = new Wall(0,0);
private static Rock rockTest = new Rock(40,80);
private static Baba babaTest = new Baba(80,80);
private static Is isTest = new Is(80,40);
private static Win winObj = new Win(80,120 );
@Test
void atObjectLocation() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(wallTest);
assertEquals(DemoRuleOne.babaObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.babaObj.getY(), rtnObj.getY());
}
@Test
void nearObjectRight() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(babaTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectLeft() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(rockTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectUp() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(isTest);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
@Test
void nearObjectDown() {
GeneralObject rtnObj = DemoRuleOne.atObjectLocation(winObj);
assertEquals(DemoRuleOne.isObj.getX(), rtnObj.getX());
assertEquals(DemoRuleOne.isObj.getY(), rtnObj.getY());
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment