import junit.framework.TestCase;

/**
 * A JUnit test case class of the Strategy2 with both
 * array and ArrayList storage of the phones in 
 * the conversation.
 */
public class Strategy2Tester extends TestCase {
  
  /**
   * Test makeCall and toString with 
   * array implementation
     */
  public void testMakeCallArray() {
    
    Strategy s = new Strategy2( 5 );
    
    Phone p1 = new Phone( "1234567" );
    Phone p2 = new Phone( "2345678" );
    
    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    
    assertEquals( "2345678\n1234567\n", s.toString() );
    
    //System.out.println( s.toString() );
  }
  
  /**
   * Test makeCall and hangUp
   * with array implementation
   */
  public void testHangUpArray() {
    
    Strategy s = new Strategy2( 10 );
    
    Phone p1 = new Phone( "1234567" );
    Phone p2 = new Phone( "2345678" );
    Phone p3 = new Phone( "3456789" );
    Phone p4 = new Phone( "4567890" );
    Phone p5 = new Phone( "5678901" );
    Phone p6 = new Phone( "6789012" );
    Phone p7 = new Phone( "7890123" );
    Phone p8 = new Phone( "8901234" );

    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    s.makeCall( p2, p3 );
    s.makeCall( p2, p4 );
    s.makeCall( p1, p5 );    
    s.makeCall( p2, p6 );
    s.makeCall( p3, p7 );
    s.makeCall( p1, p8 );
    assertEquals( "8901234\n7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p8 );
    assertEquals( "7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );    
    s.makeCall( p1, p8 );    
    assertEquals( "8901234\n7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );

    s.hangUp( p4 );
    assertEquals( "8901234\n7890123\n6789012\n5678901\n3456789\n2345678\n1234567\n", s.toString() );
    s.hangUp( p3 );
    assertEquals( "8901234\n6789012\n5678901\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
  }
  
  /**
   * Test makeCall and toString with 
   * ArrayList implementation
   */
  public void testMakeCallArrayList() {
    
    Strategy s = new Strategy2();
    
    Phone p1 = new Phone( "1234567" );
    Phone p2 = new Phone( "2345678" );
    
    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    
    assertEquals( "2345678\n1234567\n", s.toString() );
    
    //System.out.println( s.toString() );
  }
  
  /**
   * Test makeCall and hangUp
   * with ArrayList implementation
   */
  public void testHangUpArrayList() {
    
    Strategy s = new Strategy2();
    
    Phone p1 = new Phone( "1234567" );
    Phone p2 = new Phone( "2345678" );
    Phone p3 = new Phone( "3456789" );
    Phone p4 = new Phone( "4567890" );
    Phone p5 = new Phone( "5678901" );
    Phone p6 = new Phone( "6789012" );
    Phone p7 = new Phone( "7890123" );
    Phone p8 = new Phone( "8901234" );

    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    s.makeCall( p2, p3 );
    s.makeCall( p2, p4 );
    s.makeCall( p1, p5 );    
    s.makeCall( p2, p6 );
    s.makeCall( p3, p7 );
    s.makeCall( p1, p8 );
    assertEquals( "8901234\n7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p8 );
    assertEquals( "7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );    
    s.makeCall( p1, p8 );    
    assertEquals( "8901234\n7890123\n6789012\n5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );

    s.hangUp( p4 );
    assertEquals( "8901234\n7890123\n6789012\n5678901\n3456789\n2345678\n1234567\n", s.toString() );
    s.hangUp( p3 );
    assertEquals( "8901234\n6789012\n5678901\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );

  }  
}

