Android Open Source - Handalfabet Game Logic Test






From Project

Back to project page Handalfabet.

License

The source code is released under:

GNU General Public License

If you think the Android project Handalfabet 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 com.example.SwedishSignAlphabet;
import android.test.AndroidTestCase;
import android.util.Log;
/* w  ww.j  a v  a 2  s .c  om*/
import com.example.SwedishSignAlphabet.Game;
import com.example.SwedishSignAlphabet.GameLogic;

/**
 *    Copyright? 2012, Grupp02
 * 
 *     This file is part of Handalfabetet.
 *
 *   Handalfabetet is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Handalfabetet is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Handalfabetet.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The GameLogicTest class is a testclass to test the GameLogic for Game.
 * 
 * @author  : Grupp02
 * @version : 2012-10-19, v1.0
 *
 */
public class GameLogicTest extends AndroidTestCase {
  
  private GameLogic gameLogic1;
  private GameLogic gameLogic2;
  private GameLogic gameLogic3;
  private Game game;
  

  protected void setUp() throws Exception {
    game = new Game();
    gameLogic1 = new GameLogic(1,1,game);
    gameLogic2 = new GameLogic(1,2,game);
    gameLogic3 = new GameLogic(1,3,game);
    super.setUp();
  }

  protected void tearDown() throws Exception {
    super.tearDown();
  }
  
  /**
   *  A simple test for score value.
   *  Difficult 1
   */
  public void simpleTestScore1() {
    gameLogic1.scoreCounter();
    assertEquals(gameLogic1.getRoundScore(), gameLogic1.getTotalScore() );   
  }
  /**
   *  A simple test for score value.
   *  Difficult 2
   */
  public void simpleTestScore2() {
    gameLogic2.scoreCounter();
    assertEquals(gameLogic2.getRoundScore(), gameLogic2.getTotalScore() );   
  }
  /**
   *  A simple test for score value.
   *  Difficult 3
   */
  public void simpleTestScore3() {
    gameLogic1.scoreCounter();
    assertEquals(gameLogic3.getRoundScore(), gameLogic3.getTotalScore() );   
  }
  
  /**
   * Simulates a test for score after 10 rounds.
   */
  public void simpleTestScore10times() {
    for(int i = 0; i < 10; i++) {
      simpleTestScore1();
    }
  }
  
  
  /**
   * Tests if the tree answersbuttons gets unique strings.
   * Difficult 1 .
   */
  public void testUniqueRandomizedLetters() {
    
    gameLogic1.determineChoices();
    assertFalse(gameLogic1.getFirstButtonString()
               .equals(
            gameLogic1.getSecondButtonString()));
    
    assertFalse(gameLogic1.getFirstButtonString()
               .equals(
          gameLogic1.getThirdButtonString()));
    
    assertFalse(gameLogic1.getSecondButtonString()
               .equals(
          gameLogic1.getThirdButtonString()));
    
    
    Log.e("",gameLogic1.getFirstButtonString());
    Log.e("",gameLogic1.getSecondButtonString());
    Log.e("",gameLogic1.getThirdButtonString());
    
    
  }
  
  /**
   * Test if the answer buttons contains the correct answer
   * For difficulty 1.
   */
  public void testIfAnswersButtonsContainsTheCorrextAnswer1() {
    
    gameLogic1.determineChoices();
    
    Log.e("","<<<"+  gameLogic1.getFirstPicture());
    Log.e("","<<<"+  gameLogic1.getFirstButtonString());
    
    assertTrue(  gameLogic1.getFirstButtonString().equals(
          gameLogic1.getFirstPicture())
          ||
          gameLogic1.getSecondButtonString().equals(
          gameLogic1.getFirstPicture()) 
          ||
          gameLogic1.getThirdButtonString().equals(
          gameLogic1.getFirstPicture()) 
          );
    
    
  }
  
  /**
   * Runs the tests method 10 times.
   * This tests has the O(n^3) so this limits the test to 10 rounds.
   */
  public void testUniqueRandomizedLetters10times() {
    for(int i = 0; i < 10; i++) {
      testUniqueRandomizedLetters();
    }
  }
  
  /**
   * Tests if the tree answersbuttons gets unique strings. 
   * Difficult 2.
   */
  public void testUniqueRandomizedLetters2() {
    
    gameLogic2.determineChoices();
    assertFalse(gameLogic2.getFirstButtonString()
               .equals(
            gameLogic2.getSecondButtonString()));
    
    assertFalse(gameLogic2.getFirstButtonString()
               .equals(
          gameLogic2.getThirdButtonString()));
    
    assertFalse(gameLogic2.getSecondButtonString()
               .equals(
          gameLogic2.getThirdButtonString()));
    
    
    Log.e("",gameLogic2.getFirstButtonString());
    Log.e("",gameLogic2.getSecondButtonString());
    Log.e("",gameLogic2.getThirdButtonString());
    
    
  }
  
  /**
   * Tests if the tree answersbuttons gets unique strings. 
   * Difficult 3 .
   */
  public void testUniqueRandomizedLetters3() {
    
    gameLogic3.determineChoices();
    assertFalse(gameLogic3.getFirstButtonString()
               .equals(
            gameLogic3.getSecondButtonString()));
    
    assertFalse(gameLogic3.getFirstButtonString()
               .equals(
          gameLogic3.getThirdButtonString()));
    
    assertFalse(gameLogic3.getSecondButtonString()
               .equals(
          gameLogic3.getThirdButtonString()));
    
    
    Log.e("",gameLogic3.getFirstButtonString());
    Log.e("",gameLogic3.getSecondButtonString());
    Log.e("",gameLogic3.getThirdButtonString());
    
    
  }
  /**
   * Test if the answer buttons contains the correct answer
   * For difficulty 2.
   */
  public void testIfAnswersButtonsContainsTheCorrextAnswer2() {
    
    gameLogic2.determineChoices();
    
    Log.e("","<<<"+  gameLogic2.getFirstPicture() 
              + gameLogic2.getSecondPicture());

    Log.e("","<<<"+  gameLogic2.getFirstButtonString());
    Log.e("","<<<"+  gameLogic2.getSecondButtonString());
    Log.e("","<<<"+  gameLogic2.getThirdButtonString());
    
    assertTrue(  gameLogic2.getFirstButtonString().equals(
               gameLogic2.getFirstPicture()
               +gameLogic2.getSecondPicture())
          ||
          gameLogic2.getSecondButtonString().equals(
               gameLogic2.getFirstPicture()
               +gameLogic2.getSecondPicture()) 
          ||
          gameLogic2.getThirdButtonString().equals(
               gameLogic2.getFirstPicture()
               +gameLogic2.getSecondPicture()) 
          );
    
    
  }
  
  /**
   * Test if the answer buttons contains the correct answer
   * For difficulty 3.
   */
  public void testIfAnswersButtonsContainsTheCorrextAnswer3() {
    
    gameLogic3.determineChoices();
    
    Log.e("","<<<"+  gameLogic3.getFirstPicture()
            +  gameLogic3.getSecondPicture()
            + gameLogic3.getThirdPicture());
    
    Log.e("","<<<"+  gameLogic3.getFirstButtonString());
    Log.e("","<<<"+  gameLogic3.getSecondButtonString());
    Log.e("","<<<"+  gameLogic3.getThirdButtonString());
    
    assertTrue(  gameLogic3.getFirstButtonString().equals(
              gameLogic3.getFirstPicture()
              +gameLogic3.getSecondPicture()
              +gameLogic3.getThirdPicture())
          ||
          gameLogic3.getSecondButtonString().equals(
              gameLogic3.getFirstPicture()
              +gameLogic3.getSecondPicture()
              +gameLogic3.getThirdPicture()) 
          ||
          gameLogic3.getThirdButtonString().equals(
              gameLogic3.getFirstPicture()
              +gameLogic3.getSecondPicture()
              +gameLogic3.getThirdPicture()) 
          );
    
    
  }

}




Java Source Code List

com.SwedishSignAlphabet.AlphabetHelpActivity.java
com.SwedishSignAlphabet.AudioFocusHelper.java
com.SwedishSignAlphabet.CreateNewPlayer.java
com.SwedishSignAlphabet.DatabaseHelper.java
com.SwedishSignAlphabet.DisplayHighscoreActivity.java
com.SwedishSignAlphabet.GameEnd.java
com.SwedishSignAlphabet.GameHelpActivity.java
com.SwedishSignAlphabet.GameLogic.java
com.SwedishSignAlphabet.GameSettingsActivity.java
com.SwedishSignAlphabet.Game.java
com.SwedishSignAlphabet.Help.java
com.SwedishSignAlphabet.HighScoreArrayAdapter.java
com.SwedishSignAlphabet.HighScore.java
com.SwedishSignAlphabet.ImagePickActivity.java
com.SwedishSignAlphabet.LevelChooserActivity.java
com.SwedishSignAlphabet.MainActivity.java
com.SwedishSignAlphabet.PhotoHandler.java
com.SwedishSignAlphabet.ProfileSettingsActivity.java
com.SwedishSignAlphabet.SoundPlayer.java
com.SwedishSignAlphabet.SoundSettingsActivity.java
com.SwedishSignAlphabet.SoundSettings.java
com.SwedishSignAlphabet.UserActivity.java
com.SwedishSignAlphabet.UserArrayAdapter.java
com.SwedishSignAlphabet.User.java
com.example.SwedishSignAlphabet.CreateNewPlayerActivityTest.java
com.example.SwedishSignAlphabet.DatabaseHelperTest.java
com.example.SwedishSignAlphabet.GameActivityTest.java
com.example.SwedishSignAlphabet.GameLogicTest.java
com.example.SwedishSignAlphabet.MainActivityTest.java
com.example.SwedishSignAlphabet.UserActivityTest.java
com.example.SwedishSignAlphabet.UserTest.java
com.example.android.AlphabetHelpActivity.java
com.example.android.AudioFocusHelper.java
com.example.android.CreateNewPlayer.java
com.example.android.DatabaseHelper.java
com.example.android.DisplayHighscoreActivity.java
com.example.android.GameEnd.java
com.example.android.GameHelpActivity.java
com.example.android.GameLogic.java
com.example.android.GameSettingsActivity.java
com.example.android.Game.java
com.example.android.Help.java
com.example.android.HighScoreArrayAdapter.java
com.example.android.HighScore.java
com.example.android.ImagePickActivity.java
com.example.android.LevelChooserActivity.java
com.example.android.MainActivity.java
com.example.android.PhotoHandler.java
com.example.android.ProfileSettingsActivity.java
com.example.android.SoundPlayer.java
com.example.android.SoundSettingsActivity.java
com.example.android.SoundSettings.java
com.example.android.UserActivity.java
com.example.android.UserArrayAdapter.java
com.example.android.User.java