import junit.framework.TestCase;

/**
 * A JUnit test case class of the Strategy1 with both
 * array and ArrayList storage of the phones in 
 * the conversation.
 */
public class Strategy1Tester extends TestCase {
  
  /**
   * Test makeCall and toString with 
   * array implementation
     */
  public void testMakeCallArray() {
    
    Strategy s = new Strategy1( 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 Strategy1( 5 );
    
    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" );
    
    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    s.makeCall( p1, p3 );
    s.makeCall( p2, p4 );
    s.makeCall( p1, p5 );    
    assertEquals( "5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p5 );
    assertEquals( "4567890\n3456789\n2345678\n1234567\n", s.toString() );    
    s.makeCall( p1, p5 );    
    assertEquals( "5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p3 );
    assertEquals( "2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
  }
  
  /**
   * Test makeCall and toString with 
   * ArrayList implementation
   */
  public void testMakeCallArrayList() {
    
    Strategy s = new Strategy1();
    
    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 Strategy1();
    
    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" );
    
    s.makeCall( null, p1 );
    s.makeCall( p1, p2 );
    s.makeCall( p1, p3 );
    s.makeCall( p2, p4 );
    s.makeCall( p1, p5 );    
    assertEquals( "5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p5 );
    assertEquals( "4567890\n3456789\n2345678\n1234567\n", s.toString() );    
    s.makeCall( p1, p5 );    
    assertEquals( "5678901\n4567890\n3456789\n2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
    
    s.hangUp( p3 );
    assertEquals( "2345678\n1234567\n", s.toString() );
    //System.out.println( s.toString() );
  }
  
}

