// // FILE: CellGridTest.java // AUTHOR: Eugene Wallingford // DATE: 2012/10/13 // COMMENT: This test case demonstrates a 2x2 grid of Cells // and sequences of moves leading to wins. // // MODIFIED: 2012/10/14 -- Eugene Wallingford // CHANGE: changed labels to make directions clearer // // MODIFIED: 2012/10/17 -- Eugene Wallingford // CHANGE: changed name of isWin() to isStraight() // import junit.framework.TestCase; public class CellGridTest extends TestCase { private Cell upperLeft; private Cell lowerLeft; private Cell upperRight; private Cell lowerRight; protected void setUp() { upperLeft = new Cell(); lowerLeft = new Cell(); upperRight = new Cell(); lowerRight = new Cell(); upperLeft.accept( 'E', upperRight ); upperLeft.accept( 'S', lowerLeft ); upperRight.accept( 'W', upperLeft ); upperRight.accept( 'S', lowerRight ); lowerLeft.accept( 'E', lowerRight ); lowerLeft.accept( 'N', upperLeft ); lowerRight.accept( 'W', lowerLeft ); lowerRight.accept( 'N', upperRight ); } public void testSimpleStraight() { lowerLeft.move ( 'N', 'x' ); upperRight.move( 'W', 'o' ); lowerLeft.move ( 'N', 'x' ); assertTrue( lowerLeft.isStraight( 'N' ) ); } public void testLongerStraight() { lowerLeft.move ( 'N', 'x' ); upperLeft.move ( 'S', 'o' ); upperRight.move( 'W', 'x' ); upperLeft.move ( 'S', 'o' ); assertTrue( upperLeft.isStraight( 'S' ) ); } public void testDiscoveredStraight() { lowerLeft.move ( 'N', 'x' ); upperRight.move( 'W', 'o' ); upperRight.move( 'W', 'x' ); upperRight.move( 'W', 'o' ); assertTrue( lowerLeft.isStraight( 'N' ) ); } public void testTwoDiscoveredStraights() { lowerLeft.move ( 'N', 'x' ); upperRight.move( 'W', 'o' ); upperRight.move( 'S', 'x' ); upperRight.move( 'W', 'o' ); assertTrue( upperLeft.isStraight( 'S' ) ); assertTrue( upperRight.isStraight( 'S' ) ); } }