Package crazyOrb.mechanics.test

Source Code of crazyOrb.mechanics.test.MoveControllerTest

package crazyOrb.mechanics.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;

import crazyOrb.mechanics.Ball;
import crazyOrb.mechanics.DropableFigure;
import crazyOrb.mechanics.MoveBallDirection;
import crazyOrb.mechanics.MoveController;
import crazyOrb.mechanics.NotifiedObject;
import crazyOrb.mechanics.Playground;
import crazyOrb.mechanics.RepaintComponent;

public class MoveControllerTest {

  private NotifiedObject notObject = new NotifiedObject() {
    @Override
    public void repaint(RepaintComponent component) {}

    @Override
    public void lostAllLifes() {}

    @Override
    public void ballCrashedWithBlock() {}
  };

  private MoveController moveController;
  private Playground spielFeld;
  private Ball ball;

  @Before
  public void setUp() throws Exception {
    moveController = new MoveController(notObject);
    spielFeld = moveController.getPlayground();
    ball = spielFeld.getBall();
  }

  @Test
  public void testMoveController() {
    assertTrue("Nach dem Initialisieren ist das Spiel pausiert!", moveController.isPaused());
  }

  @Test
  public void testMoveBall() {
    moveController.terminate();
    moveController.resume();
    assertEquals("Der Ball muss in der Mitte des Spielfelds initialisiert werden!!",
        (spielFeld.getWidth()/2), (ball.getxPos()));
    for(int i = 0; i < spielFeld.getWidth(); i++){
      int ballBefore = ball.getxPos();
      moveController.moveBall(MoveBallDirection.DIRECTION_LEFT);
      if(ballBefore == 0){
        assertEquals("Der Ball darf sich am Rand nicht bewegen", 0, ballBefore);
      }else
        assertEquals("Der Ball muss sich in die angegebene Richtung bewegen!",
            ballBefore + MoveBallDirection.getDirection(MoveBallDirection.DIRECTION_LEFT),
            ball.getxPos());
    }
  }

  private int[] getArrayYPos(LinkedList<DropableFigure> blocks) {
    int[] blockYPos = new int[blocks.size()];
    for(int i = 0; i < blocks.size(); i++){
      blockYPos[i] = blocks.get(i).getyPos();
    }
    return blockYPos;
  }

  @Test
  public void testMoveBlocks() {
    int[] blocksBefore;
    int[] blocksAfter;
    for(int i = 0; i < spielFeld.getHeight() - 2; i++){
      moveController.addBlocks();
      blocksBefore = getArrayYPos(spielFeld.getBlocks());
      blocksAfter = getArrayYPos(spielFeld.getBlocks());

      for(int j = 0; j < blocksAfter.length; j++){
        assertEquals("Nach dem Bewegen der Blocks müssen die Y-Pos inkrementiert werden!",
            blocksBefore[j] + 1, blocksAfter[j]);
      }
    }
  }

}
TOP

Related Classes of crazyOrb.mechanics.test.MoveControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.