@Test public void addBallTest() { assertEquals(model.getBalls(), new ArrayList<Ball>()); model.addBall("b1", 10, 10, 50, 50); model.addBall("b2", 10, 10, 50, 50); assertTrue(model.getBalls().size() == 1); }
@Test public void setAbsorberTest() { Absorber absorb = new Absorber("absorb", 0, 0, 60, 60); model.setAbsorber(absorb); assertTrue(model.getAbsorber() != null); assertEquals(model.getAbsorber(), absorb); }
@Override public void mouseClicked(MouseEvent mouseEvent) { Board b = bgui.getGridView(); if (b.getAction() == Board.Action.ADD && bgui.getSelectedComponent().equals("Gizmo")) { String gizmoShape = bgui.getGizmoShape(); Point mouseP = MouseInfo.getPointerInfo().getLocation(); Point gridP = b.getLocationOnScreen(); int x = mouseP.x - gridP.x; int y = mouseP.y - gridP.y; boolean added = false; switch (gizmoShape) { case "Circle": added = m.addCircularBumper(x, y, 0, "circle"); break; case "Triangle": added = m.addTriangularBumper(x, y, 0, "triangle"); break; case "Square": added = m.addSquareBumper(x, y, 0, "square"); break; case "Teleporter": added = m.addTeleporterBumper(x, y, 0, "teleporter"); break; default: } if (added) { bgui.setMessageColor(Color.GREEN); bgui.setMessage(gizmoShape + " added!"); } else { bgui.setMessageColor(Color.RED); bgui.setMessage("That space is occupied, " + gizmoShape + " cannot be added"); } } }
@Test public void frictionTest() { assertTrue(model.getFrictionX() == 0.025); assertTrue(model.getFrictionY() == 0.025); model.setFriction(1.5, 1.5); assertTrue(model.getFrictionX() == 1.5); assertTrue(model.getFrictionY() == 1.5); }
@Test public void setFlippersTest() { List<Flipper> flippers = new ArrayList<Flipper>(); Flipper flip = new Flipper(0, 0, true, "flip"); flippers.add(flip); model.setFlippers(flippers); assertTrue(model.getFlippers().size() == 1); assertEquals(model.getFlippers().get(0), flip); }
@Test public void setBallsTest() { List<Ball> balls = new ArrayList<Ball>(); Ball ball = new Ball("b1", 5, 5, 50, 50); balls.add(ball); model.setBalls(balls); assertTrue(model.getBalls().size() == 1); assertEquals(model.getBalls().get(0), ball); }
@Test public void setGizmosTest() { List<Bumper> bumpers = new ArrayList<Bumper>(); Bumper cBump = new CircularBumper(0, 0, 0, "cBump"); bumpers.add(cBump); model.setBumpers(bumpers); assertTrue(model.getBumpers().size() == 1); assertEquals(model.getBumpers().get(0), cBump); }
@Test public void keyConnectionTest() { assertTrue(model.addKeyConnectionAbs(10, new Absorber("ABS1", 0, 380, 400, 400), "down")); assertTrue(model.getKeyConnectionsAbs().size() == 1); assertTrue(model.getKeyConnectionsAbs().get(0).getKeyID() == 10); assertTrue(model.addKeyConnectionFlipper(20, new Flipper(0, 0, true, "F1"), "down")); assertTrue(model.getKeyConnectionsFlipper().size() == 1); assertTrue(model.getKeyConnectionsFlipper().get(0).getKeyID() == 20); }
@Test public void connectionTest() { CircularBumper circularBumper = new CircularBumper(100, 100, 0, "cBump"); Flipper flipper = new Flipper(200, 200, true, "f1"); assertEquals(model.getConnections(), new ArrayList<Connection>()); model.addConnection(circularBumper, flipper); assertTrue(model.getConnections().size() == 1); model.addConnection(circularBumper, flipper); assertTrue(model.getConnections().size() == 1); }
@Test public void occupiedSpacesTest() { boolean[][] occupied = model.getOccupiedSpaces(); for (int i = 0; i < occupied.length; i++) { for (int j = 0; j < occupied[i].length; j++) { assertFalse(occupied[i][j]); } } model.addCircularBumper(0, 0, 0, "cBump"); assertTrue(model.getOccupiedSpaces()[0][0]); }
@Override public void keyPressed(KeyEvent keyEvent) { Board b = bgui.getGridView(); if (b.getAction() == Board.Action.KEY_DISCONNECT) { if (f != null) { boolean removed = false; for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) { if (kcf.getFlipper().equals(f) && (kcf.getKeyID() == keyEvent.getKeyCode())) { m.getKeyConnectionsFlipper().remove(kcf); bgui.setMessageColor(Color.GREEN); bgui.setMessage("Key '" + KeyEvent.getKeyText(kcf.getKeyID()) + "' is removed!"); removed = true; break; } } if (!removed) { bgui.setMessageColor(Color.RED); bgui.setMessage( "Key '" + KeyEvent.getKeyText(keyEvent.getKeyCode()) + "' is not connected " + " to that flipper! "); } } else if (abs != null) { boolean removed = false; for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) { if ((kca.getKeyID() == keyEvent.getKeyCode())) { m.getKeyConnectionsAbs().remove(kca); bgui.setMessageColor(Color.GREEN); bgui.setMessage("Key '" + KeyEvent.getKeyText(kca.getKeyID()) + "' is removed!"); removed = true; break; } } if (!removed) { bgui.setMessageColor(Color.RED); bgui.setMessage( "Key '" + KeyEvent.getKeyText(keyEvent.getKeyCode()) + "' is not connected " + " to that absorber! "); } } else { bgui.setMessageColor(Color.YELLOW); bgui.setMessage("No Component chosen yet"); } } }
@Test public void deleteElementTest() { assertFalse(model.deleteElement(0, 0)); model.addSquareBumper(0, 0, 0, "sBump"); assertTrue(model.deleteElement(0, 0)); model.addFlipper(0, 0, true, "flipper"); assertTrue(model.deleteElement(0, 0)); model.addAbsorber("absorb", 0, 0, 20, 20); assertTrue(model.deleteElement(0, 0)); model.addBall("b1", 10, 10, 50, 50); assertTrue(model.deleteElement(0, 0)); }
@Test public void moveElementTest() { assertFalse(model.moveElement(0, 0, 60, 60)); model.addSquareBumper(40, 0, 0, "sBump"); model.addFlipper(0, 0, true, "flipper"); model.addAbsorber("absorb", 0, 40, 100, 60); model.addBall("b1", 70, 10, 50, 50); assertFalse(model.moveElement(40, 0, 0, 0)); assertFalse(model.moveElement(0, 0, 20, 0)); assertTrue(model.moveElement(40, 0, 80, 0)); assertTrue(model.moveElement(0, 40, 0, 80)); assertTrue(model.moveElement(0, 0, 0, 40)); assertTrue(model.moveElement(60, 0, 10, 10)); }
@Test public void moveBallTest() { model.addSquareBumper(40, 0, 0, "sBump"); model.addFlipper(60, 60, false, "flipper"); model.addAbsorber("absorb", 0, 180, 200, 200); model.addBall("b1", 10, 10, 50, 50); model.moveModel(); assertTrue(model.getBalls().get(0).getX() != 10); assertTrue(model.getBalls().get(0).getY() != 10); model.reset(); assertTrue(model.getBalls().get(0).getX() == 10); assertTrue(model.getBalls().get(0).getX() == 10); }
@Test public void objectNameTest() { assertTrue(model.getObjectTypeForKeyConnection("sBump") == null); model.addSquareBumper(40, 0, 0, "sBump"); assertTrue(model.getObjectTypeForKeyConnection("sBump") == null); model.addFlipper(60, 60, false, "flipper"); model.addAbsorber("absorb", 0, 180, 200, 200); assertEquals(model.getObjectTypeForKeyConnection("flipper"), "Flipper"); assertEquals(model.getObjectTypeForKeyConnection("absorb"), "Absorber"); }
@Test public void clearTest() { model.addSquareBumper(0, 0, 0, "sBump"); model.addCircularBumper(0, 20, 0, "cBump"); model.addTriangularBumper(0, 40, 0, "tBump"); model.clear(); assertTrue(model.getBumper("sBump") == null); assertTrue(model.getBumper("cBump") == null); assertTrue(model.getBumper("tBump") == null); assertTrue(model.getBumpers().size() == 0); }
@Test public void rotateElementTest() { assertFalse(model.rotateElement(0, 0)); model.addTriangularBumper(0, 40, 0, "tBump"); model.addFlipper(0, 0, true, "flipper"); assertTrue(model.rotateElement(0, 40)); assertTrue(model.getBumper("tBump").getRotation() == 1); assertTrue(model.rotateElement(0, 0)); }
@Test public void addFlipperTest() { model.addFlipper(0, 0, true, "flipper"); assertTrue(model.getFlippers().size() == 1); model.addFlipper(0, 0, true, "flipper"); assertTrue(model.getFlippers().size() == 1); model.addFlipper(60, 0, true, "flipper"); assertTrue(model.getFlippers().size() == 2); }
@Override public void mouseClicked(MouseEvent mouseEvent) { Board b = bgui.getGridView(); if (b.getAction() == Board.Action.KEY_DISCONNECT) { Point mouseP = MouseInfo.getPointerInfo().getLocation(); Point gridP = b.getLocationOnScreen(); int x = mouseP.x - gridP.x; int y = mouseP.y - gridP.y; x -= x % 20; y -= y % 20; f = m.findFlipper(x, y); String keys = ""; if (f != null) { for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) { if (kcf.getFlipper().equals(f)) { keys += ("'" + KeyEvent.getKeyText(kcf.getKeyID()) + "', "); } } if (keys.length() > 2) { keys = keys.substring(0, keys.length() - 2); } abs = null; b.requestFocus(); bgui.setMessageColor(Color.BLACK); bgui.setMessage( "This flipper is connected to keys " + keys + ". Press key to remove connection to it."); } else if (m.getAbsorber() != null && x <= m.getAbsorber().getXBottomRight() && x >= m.getAbsorber().getXTopLeft() && y <= m.getAbsorber().getYBottomRight() && y >= m.getAbsorber().getYTopLeft()) { for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) { keys += ("'" + KeyEvent.getKeyText(kca.getKeyID()) + "', "); } if (keys.length() > 2) { keys = keys.substring(0, keys.length() - 2); } abs = m.getAbsorber(); b.requestFocus(); bgui.setMessageColor(Color.BLACK); bgui.setMessage( "This absorber is connected to keys " + keys + ". Press key to remove connection to it."); } } }
@Test public void addAbsorberTest() { assertTrue(model.getAbsorber() == null); model.addAbsorber("absorb", 0, 0, 20, 20); model.addAbsorber("absorb", 0, 20, 60, 80); assertFalse(model.getAbsorber() == null); assertTrue(model.getAbsorber().getXTopLeft() == 0); assertTrue(model.getAbsorber().getYTopLeft() == 20); assertTrue(model.getAbsorber().getXBottomRight() == 60); assertTrue(model.getAbsorber().getYBottomRight() == 80); }
@Test public void gravityTest() { assertTrue(model.getGravity() == 25); model.setGravity(50); assertTrue(model.getGravity() == 50); }
@Test public void fileTest() { assertTrue(model.getLoadFile() == null); model.setLoadFile(new File("test.txt")); assertEquals(model.getLoadFile(), new File("test.txt")); }
@Test public void addBumpersTest() { model.addSquareBumper(0, 0, 0, "sBump"); model.addCircularBumper(0, 20, 0, "cBump"); model.addTriangularBumper(0, 40, 0, "tBump"); assertFalse(model.getBumper("sBump") == null); assertTrue(model.getBumper("") == null); assertTrue(model.getBumper("sBump") instanceof SquareBumper); assertTrue(model.getBumper("cBump") instanceof CircularBumper); assertTrue(model.getBumper("tBump") instanceof TriangularBumper); model.addSquareBumper(0, 0, 0, "sBump"); model.addCircularBumper(0, 20, 0, "cBump"); model.addTriangularBumper(0, 40, 0, "tBump"); assertTrue(model.getBumpers().size() == 3); }