Android Open Source - iSlide Move Test






From Project

Back to project page iSlide.

License

The source code is released under:

MIT License

If you think the Android project iSlide 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 edu.csun.group2.islide.engine;
/*ww  w . j a  v  a 2  s.c o m*/
import static org.junit.Assert.*;

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

public class MoveTest {

  Board start;
  Move tester;
  
  public MoveTest() {
    start = new Board(4);
    tester = new Move(start);
  }

  @Before
  public void setUp() throws Exception {
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testMove() {
    assertTrue("Failed to set parent in constructor", tester.parent == null);
    assertTrue("Failed to initialize Board", tester.ary.equals(start.ary));
    assertTrue("Failed to initialize Board", tester.ary.hashCode() == start.ary.hashCode());
  }
  
  @Test
  public void testMoveCopy(){
    int index = 0;
    while(!tester.move(index))
      index++;
    
    Move mv = new Move(tester);
    
    assertTrue("Failed to set parent in constructor", mv.parent == tester);
    assertTrue("Failed to initialize Board", mv.ary.equals(tester.ary));
    assertTrue("Failed to initialize Board", mv.ary.hashCode() == tester.ary.hashCode());
    
    assertFalse("Failed to set parent in constructor", mv.parent == start);
    assertFalse("Failed to initialize Board", mv.ary.equals(start.ary));
    assertFalse("Failed to initialize Board", mv.ary.hashCode() == start.ary.hashCode());
    
  }
  
  
  @Test
  public void testMoveDeepCopy(){
    int index = 0;
    while(!tester.move(index))
      index++;
    
    Move mv = new Move(tester, true);
    
    assertTrue("Failed to set parent in constructor", mv.parent == tester.parent);
    assertTrue("Failed to set parent in constructor", mv.parent == null);
    assertTrue("Failed to initialize Board -- g", mv.g == tester.g);
    assertTrue("Failed to initialize Board -- h", mv.h == tester.h);
    assertTrue("Failed to initialize Board -- ary", mv.ary.equals(tester.ary));
    assertTrue("Failed to initialize Board -- ary", mv.ary.hashCode() == tester.ary.hashCode());
    
    assertFalse("Failed to initialize Board -- ary", mv.ary.equals(start.ary));
    assertFalse("Failed to initialize Board -- ary", mv.ary.hashCode() == start.ary.hashCode());
    
  }
  
  
  @Test
  public void test_move(){
    Move temp = new Move(tester);
    int test_g = temp.g;
    int index = 0;
    while(!temp.move(index))
      index++;
    assertFalse("Failed to increment g", temp.g == test_g);
    assertFalse("Failed to make a move properly", temp.ary.equals(tester.ary));
  }
  

  @Test
  public void testEval() {
    Move temp = new Move(tester);
    tester.eval();
    temp.eval();
    assertTrue("Eval failed to be consistent between copies", temp.h == tester.h);
    assertTrue("Failed copy in eval test", temp.ary.equals(tester.ary));
    assertTrue("Failed copy in eval test", temp.ary.hashCode() == tester.ary.hashCode());
    
    
    for (byte i = 0; i < temp.board_size; ++i)
      temp.ary.set(i,i);
    temp.empty = 0;
    temp.eval();
    assertTrue("eval() failed to find success", temp.h == 0);
    temp.move(4);
    assertTrue("eval() failed to find success", temp.h == 2);    
  }
  
  

}




Java Source Code List

edu.csun.group2.islide.CameraPreview.java
edu.csun.group2.islide.HighScore.java
edu.csun.group2.islide.MainActivity.java
edu.csun.group2.islide.MainMenuActivity.java
edu.csun.group2.islide.PhotoHandler.java
edu.csun.group2.islide.PlayMenu.java
edu.csun.group2.islide.SelectImageActivity.java
edu.csun.group2.islide.SettingsMenu.java
edu.csun.group2.islide.TakePictureActivity.java
edu.csun.group2.islide.UtilityInfo.java
edu.csun.group2.islide.Utility.java
edu.csun.group2.islide.engine.BoardTest.java
edu.csun.group2.islide.engine.Board.java
edu.csun.group2.islide.engine.GameBoardTest.java
edu.csun.group2.islide.engine.GameBoard.java
edu.csun.group2.islide.engine.GameManager.java
edu.csun.group2.islide.engine.InputHandler.java
edu.csun.group2.islide.engine.MoveComparator.java
edu.csun.group2.islide.engine.MoveTest.java
edu.csun.group2.islide.engine.Move.java
edu.csun.group2.islide.engine.Pair.java
edu.csun.group2.islide.engine.entity.SlideTile.java
edu.csun.group2.islide.engine.entity.TileManager.java
edu.csun.group2.islide.global.GameInfo.java
edu.csun.group2.islide.interfaces.IRenderable.java
edu.csun.group2.islide.iSlide.java