import junit.framework.TestCase;

/**
 * Tester for the ClassRoom class
 */
public class ClassRoomTester extends TestCase {
  private ClassRoom c1, c2, c3;
  private AVEquipment av1, av2, av3;
  
  /**
   * Tests the first constructor and the getter methods.
   * Tests if the capacities have been initialized properly.
   */
  public void testConstructor1Capacities() {
    c1 = new ClassRoom();
    
    assertEquals("Maximum total capacity was not init to 100",
                 100,
                 c1.getMaxCapacity());
    assertEquals("Maximum seating capacity was not init to 75",
                 75,
                 c1.getMaxSeating());
    assertEquals("Current seating capacity was not init to 50",
                 50,
                 c1.getCurrSeating());
  }
  
  /**
   * Tests the first constructor. Checks if the strings were 
   * initialized properly as well as the AVEquipment.
   */
  public void testConstructor1Others() {
    c1 = new ClassRoom();
    
    assertEquals("Classroom name should be empty string",
                 "", c1.getRoomName());
    assertEquals("Owner's name should be empty string",
                 "", c1.getOwnerName());
    assertFalse("Initially there should be no AVEquipment",
                c1.hasAVEquipment());
  }
  
  /**
   * Tests that the room numbers are assigned sequentially.
   */
  public void testTotalRoomNumber() {
    c1 = new ClassRoom();
    int numRooms1 = ClassRoom.getNumRooms();
    for (int i=1; i<=10; i++)
      c1 = new ClassRoom();
    int numRooms2 = ClassRoom.getNumRooms();
    assertEquals("Room numbering is wrong",
                 10,
                 numRooms2 - numRooms1);
  }
      
  
  /**
   * Tests the second constructor.
   */
  public void testConstructor2() {
    c1 = new ClassRoom(200,150);
   
    assertEquals("Maximum total capacity was not init to 200",
                 200,
                 c1.getMaxCapacity());
    assertEquals("Maximum seating capacity was not init to 150",
                 150,
                 c1.getMaxSeating());
    assertEquals("Current seating capacity was not init to 150",
                 150,
                 c1.getCurrSeating());
    assertEquals("Classroom name should be empty string",
                 "", c1.getRoomName());
    assertEquals("Owner's name should be empty string",
                 "", c1.getOwnerName());
    assertFalse("Initially there should be no AVEquipment",
                c1.hasAVEquipment());
  }
  
  /**
   * Tests the third constructor.
   */
  public void testConstructor3() {
    c1 = new ClassRoom(150, 140, 130, "Big Hall", "Johnny");
   
    assertEquals("Maximum total capacity was not init to 150",
                 150,
                 c1.getMaxCapacity());
    assertEquals("Maximum seating capacity was not init to 140",
                 140,
                 c1.getMaxSeating());
    assertEquals("Current seating capacity was not init to 130",
                 130,
                 c1.getCurrSeating());
    assertEquals("Classroom name is wrong",
                 "Big Hall", c1.getRoomName());
    assertEquals("Owner's name is wrong",
                 "Johnny", c1.getOwnerName());
    assertFalse("Initially there should be no AVEquipment",
                c1.hasAVEquipment());
  }
  
  /**
   * Tests the getExamSeating method
   */
  public void testExamSeating() {
    c1 = new ClassRoom(210, 200, 190, "a", "b");
    assertEquals("(1) Exam seating capacity is wrong",
                 95,
                 c1.getExamSeating());
    
    c1 = new ClassRoom(210, 200, 191, "a", "b");
    assertEquals("(2) Exam seating capacity is wrong",
                 95,
                 c1.getExamSeating());
    
    c1 = new ClassRoom(210, 200, 192, "a", "b");
    assertEquals("(3) Exam seating capacity is wrong",
                 96,
                 c1.getExamSeating());
  }
  
  /**
   * Tests the hasAVEquipment, addAVEquipment and removeAVEquipment 
   * methods.
   */
  public void testAVEquipmentMethods() {
    c1 = new ClassRoom();
    assertFalse("Initially, should have no AV",
                c1.hasAVEquipment());
    c1.addAVEquipment();
    assertTrue("It should have an AV now",
               c1.hasAVEquipment());
    c1.removeAVEquipment();
    assertFalse("It should not have an AV anymore",
                c1.hasAVEquipment());
  }
  
  /**
   * Tests the getNumRooms method, but also that all three
   * constructors increase the total number of rooms as they should.
   */
  public void testTotalNumberAllConstructors() {
    int numRooms1 = ClassRoom.getNumRooms();
    for (int i=1; i<=1; i++)
      c1 = new ClassRoom();
    for (int i=1; i<=2; i++)
      c1 = new ClassRoom(10, 5);
    for (int i=1; i<=3; i++)
      c1 = new ClassRoom(10, 5, 3, "a", "b");
    int numRooms2 = ClassRoom.getNumRooms();
    
    assertEquals("The total number of rooms is wrong",
                 6,
                 numRooms2 - numRooms1);
  }
  
  /**
   * Tests the setRoomName method.
   */
  public void testSetRoomName() {
    c1 = new ClassRoom();
    
    c1.setRoomName("Hall A");
    assertEquals("(1)Room name is wrong",
                 "Hall A",
                 c1.getRoomName());
    c1.setRoomName("Hall B");
    assertEquals("(2)Room name is wrong",
                 "Hall B",
                 c1.getRoomName());
  }
  
  /**
   * Tests the setOwnerName method.
   */
  public void testSetOwnerName() {
    c1 = new ClassRoom();
    
    c1.setOwnerName("Johnny");
    assertEquals("(1)Owner's name is wrong",
                 "Johnny",
                 c1.getOwnerName());
    c1.setOwnerName("Mike");
    assertEquals("(2)Owner's name is wrong",
                 "Mike",
                 c1.getOwnerName());
  }
  
  /**
   * Tests the addSeats method
   */
  public void testAddSeats() {
    c1 = new ClassRoom(80, 60, 40, "a", "b");
    
    assertEquals("(1) Current seating is wrong",
                 40, c1.getCurrSeating());
    c1.addSeats(10);
    assertEquals("(2) Current seating is wrong",
                 50, c1.getCurrSeating());
    c1.addSeats(11);
    assertEquals("(3) Current seating is wrong",
                 60, c1.getCurrSeating());
  }
  
  /**
   * Tests the removeSeats method
   */
  public void testRemoveSeats() {
    c1 = new ClassRoom(80, 60, 40, "a", "b");    
    
    assertEquals("(1) Current seating is wrong",
                 40, c1.getCurrSeating());
    c1.removeSeats(10);
    assertEquals("(2) Current seating is wrong",
                 30, c1.getCurrSeating());
    c1.removeSeats(31);
    assertEquals("(3) Current seating is wrong",
                 0, c1.getCurrSeating());
  }
  
  /**
   * Tests the sameOwner method
   */
  public void testSameOwner() {
    c1 = new ClassRoom(10, 10, 10, "a", "Johnny");
    c2 = new ClassRoom(10, 10, 10, "a", "John");
    c3 = new ClassRoom(10, 10, 10, "a", "Johnny");
    
    assertFalse("Not the same owner", c1.hasSameOwner(c2));
    assertTrue("Same owner", c1.hasSameOwner(c3));
    assertTrue("Same classroom", c2.hasSameOwner(c2));
  }
  
  /**
   * Tests the isPortable method
   */
  public void testIsPortable() {
    c1 = new ClassRoom();
    c2 = new ClassRoom(10, 10);
    c3 = new ClassRoom(10, 10, 10, "a", "Johnny");
    
    assertFalse("All rooms are permanent", c1.isPortable());
    assertFalse("All rooms are permanent", c2.isPortable());
    assertFalse("All rooms are permanent", c3.isPortable());
  }
  
  /**
   * Tests the hasSameAVEquipment method
   */
  public void testHasSameAVEquipment() {
    c1 = new ClassRoom();
    c2 = new ClassRoom();
    
    c1.addAVEquipment();
    c2.addAVEquipment();
    
    assertFalse("Not the same AV (1)", c1.hasSameAVEquipment(c2));
    assertFalse("Not the same AV (2)", c2.hasSameAVEquipment(c1));
    assertTrue("The same AV", c1.hasSameAVEquipment(c1));
  }
  
  /**
   * Tests the areEquivalent method
   */
  public void testAreEquivalent() {
    c1 = new ClassRoom(100, 80, 60, "a", "b");
    c2 = new ClassRoom(100, 81, 60, "a", "b");
    c3 = new ClassRoom(100, 80, 61, "a", "b");
    
    assertTrue("Should be equivalent",
               ClassRoom.areEquivalent(c1, c3));
    assertFalse("Not equivalent", 
                ClassRoom.areEquivalent(c1, c2));
    assertTrue("Same classroom (obviously equivalent)",
               ClassRoom.areEquivalent(c2, c2));
  }
  
  /**
   * Tests the equals method
   */
   public void testEquals() {
     c1 = new ClassRoom(100, 80, 60, "a", "b");
     c2 = new ClassRoom(100, 80, 60, "a", "b");
     
     assertFalse("Not the same classroom", c1.equals(c2));
     assertTrue("Same classroom", c1.equals(c1));
   }
   
   /**
    * Tests the moveAVUnit method
    */
   public void testMoveAVUnit() {
     c1 = new ClassRoom();
     c2 = new ClassRoom();
     
     c1.addAVEquipment();
     assertTrue("(1) It has an AVEquipment",
                c1.hasAVEquipment());
     assertFalse("(1) It does not have an AVEquipment",
                 c2.hasAVEquipment());
     
     ClassRoom.moveAVUnit(c1, c2);
     assertTrue("(2) It has an AVEquipment",
                c2.hasAVEquipment());
     assertFalse("(2) It does not have an AVEquipment",
                 c1.hasAVEquipment());    
   }
}

