Software Engineering Fundamentals

spunja88
testing.zip

testing/.classpath

testing/.project

testing org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature

testing/.settings/org.eclipse.jdt.core.prefs

eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8

testing/bin/testing/Board.class

package testing;
public synchronized class Board {
    Snake[] snakes;
    private int SIZE;
    public void Board();
    public void addSnake(Snake) throws SnakePlacementException;
}

testing/bin/testing/junittests.class

package testing;
public synchronized class junittests {
    Board b;
    Snake s1;
    Snake s2;
    public void junittests();
    public static void setUpBeforeClass() throws Exception;
    public static void tearDownAfterClass() throws Exception;
    public void setUp() throws Exception;
    public void tearDown() throws Exception;
    public void test1() throws SnakePlacementException;
    public void test2() throws SnakePlacementException;
    public void test3() throws SnakePlacementException;
    public void test4();
    public void test5() throws SnakePlacementException;
}

testing/bin/testing/Snake.class

package testing;
public synchronized class Snake {
    int head;
    int tail;
    public void Snake(int, int);
    public int getHead();
    public int getTail();
}

testing/bin/testing/SnakePlacementException.class

package testing;
public synchronized class SnakePlacementException extends Exception {
    public void SnakePlacementException();
    public void SnakePlacementException(String);
}

testing/bin/testing/SnakeTests.class

package testing;
public synchronized class SnakeTests {
    public void SnakeTests();
    public static void setUpBeforeClass() throws Exception;
    public static void tearDownAfterClass() throws Exception;
    public void setUp() throws Exception;
    public void tearDown() throws Exception;
    public void test1();
    public void test2();
    public void test3();
}

testing/bin/testing/Test.class

package testing;
public synchronized class Test {
    Board b;
    public static void main(String[]) throws SnakePlacementException;
    public void Test() throws SnakePlacementException;
}

testing/src/testing/Board.java

testing/src/testing/Board.java

package  testing ;

public   class   Board   {
     Snake  snakes [];
     private   int  SIZE  =   100 ;
     public   Board ()
     {
        snakes  =   new   Snake [ SIZE ];
     }
    
     public   void  addSnake ( Snake  s )   throws   SnakePlacementException
     {
         if ( s . getHead () >= SIZE )
         {
             throw   new   SnakePlacementException ( "snake head out of bounds "   +  s . getHead ());
         }
         else   if ( snakes [ s . getHead ()] != null )
         {
             throw   new   SnakePlacementException ( "snake heads in same position "   +  s . getHead ());
         }
         System . out . println ( "Snake added to "   +  s . getHead ());
        snakes [ s . getHead ()] = s ;
     }
}

testing/src/testing/junittests.java

testing/src/testing/junittests.java

package  testing ;

import   static  org . junit . Assert . * ;

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

public   class  junittests  {
    
     Board  b ;
     Snake  s1 ,  s2 ;

    @ BeforeClass
     public   static   void  setUpBeforeClass ()   throws   Exception   {
         System . out . println ( "BeforeClass" );
     }

    @ AfterClass
     public   static   void  tearDownAfterClass ()   throws   Exception   {
         System . out . println ( "AfterClass" );
     }

    @ Before
     public   void  setUp ()   throws   Exception   {
        b  =   new   Board ();
        s1  =   new   Snake ( 9 , 2 );
        s2  =   new   Snake ( 10 , 3 );
         System . out . println ( "Before" );
     }

    @ After
     public   void  tearDown ()   throws   Exception   {
         System . out . println ( "After" );
     }

    @ Test
     public   void  test1 ()   throws   SnakePlacementException {
        b . addSnake ( s1 );
        assertEquals ( b . snakes [ s1 . getHead ()],  s1 );
         System . out . println ( "Test1" );
     }

    @ Test
     public   void  test2 ()   throws   SnakePlacementException {
        b . addSnake ( s1 );
        assertEquals ( b . snakes [ s1 . getHead ()],  s1 );
        b . addSnake ( s2 );
        assertEquals ( b . snakes [ s2 . getHead ()],  s2 );
         System . out . println ( "Test2" );
     }
    
    @ Test   ( expected  =   SnakePlacementException . class )
     public   void  test3 ()   throws   SnakePlacementException {
        b . addSnake ( s1 );
        s2  =   new   Snake ( s1 . getHead (),  s1 . getTail ());
        b . addSnake ( s2 );
         System . out . println ( "Test3" );
     }
    
    @ Test
     public   void  test4 ()
     {
         // mostly useless test
         // what is it testing? the constructor and a getter
         Snake  s  =   new   Snake ( 2 , 1 );
        assertEquals ( s . getHead (),   2 );
     }

    
    @ Test
     public   void  test5 ()   throws   SnakePlacementException
     {
         // Incomplete test (not precondition testing)
         Snake  s  =   new   Snake ( 2 , 1 );
        b . addSnake ( s );
        assertEquals ( s . getHead (),   2 );
        assertTrue ( b . snakes [ s . getHead ()]   ==  s );   
     }

}

testing/src/testing/Snake.java

testing/src/testing/Snake.java

package  testing ;

public   class   Snake   {
     int  head ,  tail ;
    
     public   Snake ( int  head ,   int  tail )
     {
         this . tail = tail ;
         this . head = head ;
     }
    
     public   int  getHead ()
     {
         return  head ;
     }

     public   int  getTail ()
     {
         return  tail ;
     }
}

testing/src/testing/SnakePlacementException.java

testing/src/testing/SnakePlacementException.java

package  testing ;

public   class   SnakePlacementException   extends   Exception   {

     public   SnakePlacementException ()
     {
        
     }
    
     public   SnakePlacementException ( String  mesg )
     {
         super ( mesg );
     }
}

testing/src/testing/SnakeTests.java

testing/src/testing/SnakeTests.java

package  testing ;

import   static  org . junit . Assert . * ;

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

public   class   SnakeTests   {

    @ BeforeClass
     public   static   void  setUpBeforeClass ()   throws   Exception   {
         System . out . println ( "BeforeClass" );
     }

    @ AfterClass
     public   static   void  tearDownAfterClass ()   throws   Exception   {
         System . out . println ( "AfterClass" );
     }

    @ Before
     public   void  setUp ()   throws   Exception   {
         System . out . println ( "Before" );
     }

    @ After
     public   void  tearDown ()   throws   Exception   {
         System . out . println ( "After" );
     }

    @ Test
     public   void  test1 ()   {
         System . out . println ( "Test1" );
     }

    
    @ Test
     public   void  test2 ()   {
         System . out . println ( "Test2" );
     }

    
    @ Test
     public   void  test3 ()   {
         System . out . println ( "Test3" );
     }

}

testing/src/testing/Test.java

testing/src/testing/Test.java

package  testing ;

public   class   Test   {
     Board  b ;
     public   static   void  main ( String []  args )   throws   SnakePlacementException  
     {
         // TODO Auto-generated method stub
         Test  t  =   new   Test ();
         System . out . println ( "After Test" );
     }

     public   Test ()   throws   SnakePlacementException
     {
        b  =   new   Board ();
         Snake  s  =   new   Snake ( 9 , 6 );
         Snake  s1  =   new   Snake ( 9 , 6 );
         try
         {
            b . addSnake ( s );
             System . out . println ( "After addSnake()" );
            b . addSnake ( s1 );
             System . out . println ( "After addSnake()" );
         }
         catch ( SnakePlacementException  spe )
         {
            spe . printStackTrace ();
             System . out . println ( "Exception Handled by SnakePlacementException catch" );
         }
         catch ( Exception  e )
         {
            e . printStackTrace ();
             System . out . println ( "Exception Handled by Exception catch" );          
         }
         finally
         {
             System . out . println ( "Finally" );
         }
     }
}