import junit.framework.TestCase;

/**
 * A test class for the Spy class.
 */
public class SpyTester extends TestCase {
  
  public void testGetAllCodeNumbers() {
    assertEquals("", Spy.getAllCodeNumbers());
  }
  
  public void testRemoveCodeNumber1() {
    assertFalse(Spy.removeCodeNumber(1234));
  }
  
  public void testConstructor1AndGetCodeNumber() {
    Spy s1 = new Spy(1200);
    assertEquals(1200, s1.getCodeNumber());
    assertEquals("1200", Spy.getAllCodeNumbers());
  }
  
  public void testConstructor2() {
    Spy s2 = new Spy(1200);
    assertEquals("1200", Spy.getAllCodeNumbers());
    // also make sure that a warning message is printed
  }
  
  public void testConstructor3() {
    Spy s3 = new Spy(1013);
    assertEquals("1200:1013", Spy.getAllCodeNumbers());
  }
  
  public void testConstructor4() {
    Spy s4 = new Spy(5678);
    assertEquals("5678:1200:1013", Spy.getAllCodeNumbers());
  }
  
   public void testConstructor5() {
    Spy s5 = new Spy(1015);
    assertEquals("5678:1200:1015:1013", s5.getAllCodeNumbers());
    Spy s6 = new Spy(1201);
    assertEquals("5678:1201:1200:1015:1013", s5.getAllCodeNumbers());
  }
  
  public void testRemoveCodeNumber2() {
    assertFalse(Spy.removeCodeNumber(1202));
    assertFalse(Spy.removeCodeNumber(5679));
    assertFalse(Spy.removeCodeNumber(1010));
  }
  
  public void testRemoveCodeNumber3() {
    assertTrue(Spy.removeCodeNumber(1200));
    assertTrue(Spy.removeCodeNumber(1015));
    assertEquals("5678:1201:1013", Spy.getAllCodeNumbers());
    assertTrue(Spy.removeCodeNumber(5678));
    assertEquals("1201:1013", Spy.getAllCodeNumbers());
    assertTrue(Spy.removeCodeNumber(1013));
    assertEquals("1201",Spy.getAllCodeNumbers());
    assertTrue(Spy.removeCodeNumber(1201));
    assertEquals("", Spy.getAllCodeNumbers());
  }

  public void testCharToBin1() {
    assertEquals("00100011", Spy.charToBinary('#'));
  }
  
  public void testCharToBin2() {
    assertEquals("01111001", Spy.charToBinary('y'));
  }
  
  public void testExclusiveOr1() {
    assertEquals(0, Spy.exclusiveOr(0,0));
  }
  
  public void testExclusiveOr2() {
    assertEquals(0, Spy.exclusiveOr(1,1));
  }
  
  public void testExclusiveOr3() {
    assertEquals(1, Spy.exclusiveOr(0,1));
  }
  
  public void testExclusiveOr4() {
    assertEquals(1, Spy.exclusiveOr(1,0));
  }
  
  public void testStretch1() {
    assertEquals("10010110", Spy.stretch("10010110", 6));
  }
  
  public void testStretch2() {
    assertEquals("10010110", Spy.stretch("10010110", 8));
  }
  
  public void testStretch3() {
    assertEquals("100101101111001010", Spy.stretch("10010110", 16));
  }  

  public void testEncrypt1() {    
    assertEquals("", Spy.encrypt("", 4321));
  }

  public void testEncrypt2() {    
    String msg = "Smaller Than 16";
    String expectedEncryptedMsg = "010101111011111101100101101111100110100010110111011101101111001001010000101110100110010110111100001001001110001100110010";
    assertEquals(expectedEncryptedMsg, Spy.encrypt(msg, 1234));
  }
    
  public void testEncrypt3() {
    String msg = "Larger Than 16!!!";
    String expectedEncryptedMsg = "0100100010110011011101101011010101100001101000000010010010000110011011001011001101101010111100100011010111100100001001011111001100100001";
    assertEquals(expectedEncryptedMsg, Spy.encrypt(msg, 1234));
  }    
    
  public void testDecrypt1() {
    assertEquals("", Spy.decrypt("", 1111));
  }
    
  public void testDecrypt2() {
    String msg = "Larger Than 16!!!";
    String encrypted = "0100100010110011011101101011010101100001101000000010010010000110011011001011001101101010111100100011010111100100001001011111001100100001";
    assertEquals(msg, Spy.decrypt(encrypted, 1234));
  }
  
  public void testDecrypt3() {
    String encrypted = "0100100010110011011101101011010101100001101000000010010010000110011011001011001101101010111100100011010111100100001001011111001100100001";
    assertFalse(Spy.decrypt(encrypted, 1235).equals("Larger Than 16!!!"));
  }  
    
  public void testDecrypt4() {
    String encrypted = "0100100010110011011101101011010101100001101000000010010010000110011011001011001101101010111100100011010111100100001001011111001100100001";
    String incorrectDecryptedMsg = "L`rfes Uh`n!17! !";
    assertEquals(incorrectDecryptedMsg, Spy.decrypt(encrypted, 1235));
  }  
}
