Example #1
0
  // test 14
  @Test
  public void testFileCorruption() throws Exception {

    WC counter = new WC(new String[] {"java", "WC", "src" + File.separator + "test01.txt"});
    long len = new File("src" + File.separator + "test01.txt").length();
    boolean corrupted = false;
    if (counter.count() != 0) {

      File file = new File("src" + File.separator + "test01.txt");
      if (file.length() != len) {
        corrupted = true;
      }
      FileInputStream fis = new FileInputStream(file);
      BufferedReader br = new BufferedReader(new InputStreamReader(fis));

      if (br.readLine() == null) {
        corrupted = true;
      }

      br.close();
    }
    ;

    assertFalse("The file was corrupted during processing", corrupted);
  }
Example #2
0
 // test 9
 @Test
 public void testCountNonzero() throws Exception {
   WC counter =
       new WC(new String[] {"java", "WC", "src" + File.separator + "test01.txt", "-D", "*"});
   int result = (int) counter.count();
   assertTrue("test01.txt expected average of 9, but got " + result, result == 9);
 }
Example #3
0
  // test 13
  @Test
  public void testCounterSpeed() throws Exception {
    WC counter =
        new WC(new String[] {"java", "WC", "src" + File.separator + "test01.txt", "-D", "#$"});

    Long startTime = new Long(System.currentTimeMillis());
    counter.count();
    Long endTime = new Long(System.currentTimeMillis());
    double time_taken = (endTime - startTime) / (double) 1000;
    assertTrue(
        "Expected to finish the test in less than " + counter.getWords() / 5000 + " seconds",
        time_taken < (double) counter.getWords() / 5000);
  }
Example #4
0
  // test 12
  @Test
  public void testMultipleDelimiters() throws InputError {
    WC counter =
        new WC(new String[] {"java", "WC", "src" + File.separator + "test03.txt", "-D", "#$"});
    int result = (int) counter.count();
    assertTrue("test03.txt expected average of 1, but got " + result, result == 1);

    counter = new WC(new String[] {"java", "WC", "src" + File.separator + "test03.txt", "-D", "$"});
    result = (int) counter.count();
    assertTrue("test03.txt expected average of 3, but got " + result, result == 3);

    counter =
        new WC(new String[] {"java", "WC", "src" + File.separator + "test01.txt", "-D", "#$%"});
    counter =
        new WC(new String[] {"java", "WC", "src" + File.separator + "test01.txt", "-D", "#$%^"});
  }
Example #5
0
 // test 11
 @Test
 public void testNonEmptyFile() throws InputError {
   WC counter = new WC(new String[] {"java", "WC", "src" + File.separator + "test05.txt"});
   int result = (int) counter.count();
   assertTrue("test05.txt expected average of 1, but got " + result, result == 1);
 }