Android Open Source - SeniorDesign Tile Set Test






From Project

Back to project page SeniorDesign.

License

The source code is released under:

GNU General Public License

If you think the Android project SeniorDesign 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 fakesetgame.seniordesign;
//  w  ww . jav a2  s  .com
import android.app.Application;
import android.test.ApplicationTestCase;

import junit.framework.Assert;

import java.util.Arrays;
import java.util.Random;

import fakesetgame.seniordesign.model.Color;
import fakesetgame.seniordesign.model.TileSet;
import fakesetgame.seniordesign.model.Shading;
import fakesetgame.seniordesign.model.Shape;
import fakesetgame.seniordesign.model.Tile;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class TileSetTest extends ApplicationTestCase<Application> {
    public TileSetTest() {
        super(Application.class);
    }

    Random random = new Random();

    public void testSetEvaluation_SameEverything() throws Exception {

        for (int i = 0; i < 100; i++) {
            Shape shape = Shape.valueOf(random.nextInt(3) + 1);
            Shading shading = Shading.valueOf(random.nextInt(3) + 1);
            Color color = Color.valueOf(random.nextInt(3) + 1);
            int shapeNum = random.nextInt(3) + 1;

            Tile t1 = new Tile(shape, shading, color, shapeNum);
            Tile t2 = new Tile(shape, shading, color, shapeNum);
            Tile t3 = new Tile(shape, shading, color, shapeNum);

            Assert.assertTrue(TileSet.isValidSet(t1, t2, t3));

            Tile badTile = new Tile(shape, shading, color, shapeNum % 3 + 1);
            Assert.assertFalse(TileSet.isValidSet(t1, badTile, t2));
        }
    }

    public void testSetEvaluation_DifferentEverything() throws Exception {
        int[] seed = new int[]{1, 2, 3};

        int[] rand3 = randomize(seed);
        Color[] colors = new Color[3];
        for (int i = 0; i < 3; i++)
            colors[i] = Color.valueOf(rand3[i]);

        rand3 = randomize(seed);
        Shading[] shadings = new Shading[3];
        for (int i = 0; i < 3; i++)
            shadings[i] = Shading.valueOf(rand3[i]);

        rand3 = randomize(seed);
        Shape[] shapes = new Shape[3];
        for (int i = 0; i < 3; i++)
            shapes[i] = Shape.valueOf(rand3[i]);

        int[] quantities = randomize(seed);

        Tile[] tiles = new Tile[3];
        for (int i = 0; i < 3; i++)
            tiles[i] = new Tile(shapes[i], shadings[i], colors[i], quantities[i]);

        Assert.assertTrue(TileSet.isValidSet(tiles[0], tiles[1], tiles[2]));
    }

    private int[] randomize(int[] input) {
        int[] copy = Arrays.copyOf(input, input.length);

        for (int i = copy.length - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            int temp = copy[j];
            copy[j] = copy[i];
            copy[i] = temp;
        }

        return copy;
    }
}




Java Source Code List

fakesetgame.seniordesign.BoardTest.java
fakesetgame.seniordesign.GameScreen.java
fakesetgame.seniordesign.GameTest.java
fakesetgame.seniordesign.HomeScreen.java
fakesetgame.seniordesign.OptionsScreen.java
fakesetgame.seniordesign.SettingsTest.java
fakesetgame.seniordesign.SplashScreen.java
fakesetgame.seniordesign.SummaryScreen.java
fakesetgame.seniordesign.TileSetTest.java
fakesetgame.seniordesign.data.FoundSetRecord.java
fakesetgame.seniordesign.data.GameOutcome.java
fakesetgame.seniordesign.data.GameSummaryListItemCursorAdapter.java
fakesetgame.seniordesign.data.OptionsHelper.java
fakesetgame.seniordesign.data.PlayerDataDbHelper.java
fakesetgame.seniordesign.data.Setting.java
fakesetgame.seniordesign.data.package-info.java
fakesetgame.seniordesign.model.BoardSize.java
fakesetgame.seniordesign.model.Board.java
fakesetgame.seniordesign.model.Color.java
fakesetgame.seniordesign.model.GameOverEvent.java
fakesetgame.seniordesign.model.GameOverListener.java
fakesetgame.seniordesign.model.Game.java
fakesetgame.seniordesign.model.HintProvider.java
fakesetgame.seniordesign.model.Modifier.java
fakesetgame.seniordesign.model.Shading.java
fakesetgame.seniordesign.model.Shape.java
fakesetgame.seniordesign.model.TileSet.java
fakesetgame.seniordesign.model.Tile.java
fakesetgame.seniordesign.model.package-info.java
fakesetgame.seniordesign.view.GameSummaryListItemView.java
fakesetgame.seniordesign.view.ShadedImageView.java
fakesetgame.seniordesign.view.package-info.java
fakesetgame.seniordesign.package-info.java