Android Open Source - 2048GameAndroid Board Test






From Project

Back to project page 2048GameAndroid.

License

The source code is released under:

Apache License

If you think the Android project 2048GameAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package zhengxiao.myapplication.game;
//  w  w w.jav a  2s  .c  om
import android.test.AndroidTestCase;

import com.google.common.collect.Lists;

import java.util.ArrayList;

/**
 * Created by gerald on 12/17/14.
 */
public class BoardTest extends AndroidTestCase {
    /**
     * ?????????
     */
    public void testMoveLeft() {
        Board board = new Board(Game.ROW_COUNT, Lists.newArrayList(
                8, 2, 4, 4,
                2, 2, 2, 0,
                4, 2, 4, 4,
                0, 0, 0, 2
        ));

        Board boardExpect = new Board(Game.ROW_COUNT, Lists.newArrayList(
                8, 2, 8, 0,
                4, 2, 0, 0,
                4, 2, 8, 0,
                2, 0, 0, 0
        ));


        board.moveInDirection(Direction.LEFT);

        assertEquals("move left should merge the two equal '2's", boardExpect, board);
    }

    public void testRotateBoard() {
        Board board = new Board(Game.ROW_COUNT, Lists.newArrayList(
                2, 4, 0, 0,
                0, 2, 0, 0,
                0, 0, 0, 0,
                8, 8, 8, 8
        ));

        Board boardExpect90 = new Board(Game.ROW_COUNT, Lists.newArrayList(
                8, 0, 0, 2,
                8, 0, 2, 4,
                8, 0, 0, 0,
                8, 0, 0, 0
        ));

        Board boardExpect180 = new Board(Game.ROW_COUNT, Lists.newArrayList(
                8, 8, 8, 8,
                0, 0, 0, 0,
                0, 0, 2, 0,
                0, 0, 4, 2
        ));

        Board boardExpect270 = new Board(Game.ROW_COUNT, Lists.newArrayList(
                0, 0, 0, 8,
                0, 0, 0, 8,
                4, 2, 0, 8,
                2, 0, 0, 8
        ));

        board.rotateBoardClockWise();
        assertEquals("rotate 90", boardExpect90, board);
        board.rotateBoardClockWise();
        assertEquals("rotate 180", boardExpect180, board);
        board.rotateBoardClockWise();
        assertEquals("rotate 270", boardExpect270, board);
    }

    public void testMoveInDirection(){
        Board board = new Board(Game.ROW_COUNT, Lists.newArrayList(
                2, 2, 0, 2,
                0, 2, 0, 0,
                0, 0, 0, 0,
                2, 0, 2, 2
        ));

        Board boardDown = new Board(Game.ROW_COUNT, Lists.newArrayList(
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0,
                4, 4, 2, 4
        ));

        Board boardRight = new Board(Game.ROW_COUNT, Lists.newArrayList(
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 8, 2, 4
        ));

        Board boardLeft = new Board(Game.ROW_COUNT, Lists.newArrayList(
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0,
                8, 2, 4, 0
        ));

        board.moveInDirection(Direction.DOWN);
        assertEquals("move DOWN", boardDown, board);
        board.moveInDirection(Direction.RIGHT);
        assertEquals("move RIGHT", boardRight, board);
        board.moveInDirection(Direction.LEFT);
        assertEquals("move LEFT", boardLeft, board);

    }
}




Java Source Code List

zhengxiao.myapplication.ApplicationTest.java
zhengxiao.myapplication.GameActivity.java
zhengxiao.myapplication.MainActivity.java
zhengxiao.myapplication.game.BoardTest.java
zhengxiao.myapplication.game.Board.java
zhengxiao.myapplication.game.Direction.java
zhengxiao.myapplication.game.GameTest.java
zhengxiao.myapplication.game.Game.java
zhengxiao.myapplication.game.Position.java
zhengxiao.myapplication.game.Utils.java
zhengxiao.myapplication.utils.OnGestureListenerAdapter.java