Commit cfcf3a4b authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Updated tests

parent da52dc54
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package edu.bu.ec504.hw1p3;

import edu.bu.ec504.hw1p3.compressors.CharByCharCompressor;
import edu.bu.ec504.hw1p3.compressors.LineByLineCompressor;
import edu.bu.ec504.hw1p3.compressors.MyCompressor;
import edu.bu.ec504.hw1p3.testing.Tester;
import java.io.IOException;

@@ -9,15 +10,24 @@ public class Main {
  // CONSTANTS
  private final static String URLExample = "https://en.wikipedia.org/wiki/Data_compression_ratio"; // the default URL to test
  private final static String StringExample = "can you can a can as a canner can can a can?";
   private final static String SimpleExample = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

  public static void main(String[] args) {
    try {
      //System.out.println(Tester.testUrl(new LineByLineCompressor(), URLExample));
      System.out.println(Tester.testString(new CharByCharCompressor(), StringExample));
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
      System.out.println("Trying simple example: "+SimpleExample);
      System.out.println(Tester.testString(new MyCompressor(), SimpleExample));
      System.out.println("... passed"); // if we got here, we have passed the test

      System.out.println("Trying standard example: "+StringExample);
      System.out.println(Tester.testString(new MyCompressor(), StringExample));
      System.out.println("... passed"); // if we got here, we have passed the test

      System.out.println("Trying URL example: "+URLExample);
      System.out.println(Tester.testUrl(new MyCompressor(), URLExample));
      System.out.println("... passed"); // if we got here, we have passed the test

    } catch (Exception e) {
      throw new RuntimeException("Test failed: "+e);
    }
  }
}
+7 −1
Original line number Diff line number Diff line
@@ -58,7 +58,13 @@ public class Tester {
        outDecode.close();

        // 4. Record statistics about the test
        return new TestResult(endTime - initTime, origSize, compressedSize, identical(plainFile, decompressedFile));
        boolean identicalQ = identical(plainFile, decompressedFile);
        if (!identicalQ) {
            throw new RuntimeException("original doesn't match uncompressed text: "+
                    plainFile.substring(0,10)+"... vs. "+
                    decompressedFile.substring(0,10));
        }
        return new TestResult(endTime - initTime, origSize, compressedSize, identicalQ);
    }

    /**