Esempio n. 1
0
 @Test(expected = IOException.class)
 /* Structural Basis, Bad Data */
 public void testFileNotFound() throws IOException {
   // 'text.txt' does not exist
   Segmentator segmentator = new Segmentator(1, "text.txt");
   segmentator.segmentString();
 }
Esempio n. 2
0
  @Test
  /* Structural Basis, Nominal Case */
  public void testCompressInput() throws IOException {
    // The given file will go through both parts of the if-statement.
    Segmentator seg = new Segmentator(3, "test.txt");
    Segmentator.Test test = seg.new Test();

    List<String> segmentsToCompress = seg.segmentString();

    List<Integer> actualList = test.testCompressInput(segmentsToCompress);
    List<Integer> expectedList = new ArrayList<Integer>();
    expectedList.add(0);
    expectedList.add(1);
    expectedList.add(2);
    expectedList.add(3);
    expectedList.add(4);
    expectedList.add(3);
    expectedList.add(4);
    expectedList.add(1);
    expectedList.add(5);
    expectedList.add(3);
    expectedList.add(2);
    expectedList.add(3);
    expectedList.add(1);
    expectedList.add(6);
    expectedList.add(7);
    expectedList.add(8);

    assertEquals(expectedList, actualList);
  }
Esempio n. 3
0
  @Test
  /* Structured Basis, Nominal "Good Data" Case */
  public void testStringSegments() throws IOException {
    Segmentator segmentator = new Segmentator(3, "test.txt");

    List<String> expectedSegs = new ArrayList<String>();
    expectedSegs.add("I");
    expectedSegs.add(" ");
    expectedSegs.add("cam");
    expectedSegs.add("e");
    expectedSegs.add(",");
    expectedSegs.add(" ");
    expectedSegs.add("I");
    expectedSegs.add(" ");
    expectedSegs.add("saw");
    expectedSegs.add(",");
    expectedSegs.add(" ");
    expectedSegs.add("I");
    expectedSegs.add(" ");
    expectedSegs.add("lef");
    expectedSegs.add("t");
    expectedSegs.add(".");

    assertEquals(expectedSegs, segmentator.segmentString());
  }
Esempio n. 4
0
  @Test
  /* Structural Basis, Nominal Case */
  public void testCompression() {
    Segmentator segmentator = new Segmentator(3, "test.txt");
    List<Integer> actualList = segmentator.compression();
    List<Integer> expectedList = new ArrayList<Integer>();
    expectedList.add(0);
    expectedList.add(1);
    expectedList.add(2);
    expectedList.add(3);
    expectedList.add(4);
    expectedList.add(3);
    expectedList.add(4);
    expectedList.add(1);
    expectedList.add(5);
    expectedList.add(3);
    expectedList.add(2);
    expectedList.add(3);
    expectedList.add(1);
    expectedList.add(6);
    expectedList.add(7);
    expectedList.add(8);

    assertEquals(expectedList, actualList);
  }
Esempio n. 5
0
  @Test
  /* Structural Basis, Nominal Case, No other tests needed since segmentInteger() not used in Compression */
  public void testIntegerSegments() throws IOException {
    Segmentator segmentator = new Segmentator(3, "test.txt");

    List<Integer> expectedSegs = new ArrayList<Integer>();
    expectedSegs.add(1);
    expectedSegs.add(2);
    expectedSegs.add(3);
    expectedSegs.add(4);
    expectedSegs.add(5);
    expectedSegs.add(2);
    expectedSegs.add(1);
    expectedSegs.add(2);
    expectedSegs.add(6);
    expectedSegs.add(5);
    expectedSegs.add(2);
    expectedSegs.add(1);
    expectedSegs.add(2);
    expectedSegs.add(7);
    expectedSegs.add(8);
    expectedSegs.add(9);

    assertEquals(expectedSegs, segmentator.segmentInteger());
  }
Esempio n. 6
0
  @Test
  /* Structural Basis */
  public void testEmptyFile() throws IOException {
    Segmentator segmentator = new Segmentator(1, "emptyFile.txt");
    // An empty file should skip the while !EOF and return an empty list
    List<String> expectedList = new ArrayList<String>();
    List<String> actualList = segmentator.segmentString();

    assertEquals(expectedList, actualList);
  }
Esempio n. 7
0
  @Test
  /* Structural Basis */
  public void testCompressEmptyFile() {
    Segmentator segmentator = new Segmentator(1, "emptyFile.txt");
    // Compressing an empty file should return an empty compressed list.
    List<Integer> actualList = segmentator.compression();
    List<Integer> expectedList = new ArrayList<Integer>();

    assertEquals(expectedList, actualList);
  }
Esempio n. 8
0
  @Test
  /* Structural Basis, Data Flow */
  public void testNoPunctuation() throws IOException {
    // Test file contains no punctuation
    Segmentator segmentator = new Segmentator(3, "noPunctuation.txt");
    List<String> actualList = segmentator.segmentString();
    List<String> expectedList = new ArrayList<String>();
    expectedList.add("the");
    expectedList.add("dog");
    expectedList.add("ran");
    expectedList.add("far");

    assertEquals(expectedList, actualList);
  }
Esempio n. 9
0
  @Test
  /* Structural Basis, Data Flow */
  public void testLargeTokenLength() throws IOException {
    /*
     * Segmenting a file of a single word, i.e. no punctuation, into segment length greater than the
     * number of characters in the file should put the entire word into a single token and that
     * be the only item in the returned list.
     */
    Segmentator segmentator = new Segmentator(4, "threeChars.txt");
    List<String> actualList = segmentator.segmentString();
    List<String> expectedList = new ArrayList<String>();
    expectedList.add("the");

    assertEquals(expectedList, actualList);
  }
Esempio n. 10
0
 @Test
 /* Structural Basis, Take Bad Data in and Make it Usable */
 public void testSegmentatorBadFileName() {
   /*
    *  The file 'test.txt' exists but not 'test'. This would throw an IOException error when the file
    *  is read except that I handle adding the extension if it is not there so no error should be
    *  throw in this situation.
    */
   Segmentator segmentator = new Segmentator(1, "test");
   try {
     segmentator.segmentString();
   } catch (IOException e) {
     // Should not get in here.
     e.printStackTrace();
   }
 }
Esempio n. 11
0
  @Test
  /* Structural Basis, Data Flow */
  public void testCompressInputAllSameSeg() throws IOException {
    // The file will have all the same segment and will go into the else once and then the if
    // exclusively
    Segmentator seg = new Segmentator(3, "SameSegments.txt");
    Segmentator.Test test = seg.new Test();

    List<String> segmentsToCompress = seg.segmentString();

    List<Integer> actualList = test.testCompressInput(segmentsToCompress);
    List<Integer> expectedList = new ArrayList<Integer>();
    expectedList.add(0);
    expectedList.add(0);
    expectedList.add(0);

    assertEquals(expectedList, actualList);
  }
Esempio n. 12
0
  @Test
  /* Structural Basis, Data Flow */
  public void testCompressInputAllDiffSegs() throws IOException {
    // The file will have all unique segments and thus only go into one section of if-statement (the
    // else, not the if)
    Segmentator seg = new Segmentator(2, "punctuation.txt");
    Segmentator.Test test = seg.new Test();

    List<String> segmentsToCompress = seg.segmentString();

    List<Integer> actualList = test.testCompressInput(segmentsToCompress);
    List<Integer> expectedList = new ArrayList<Integer>();
    expectedList.add(0);
    expectedList.add(1);
    expectedList.add(2);
    expectedList.add(3);

    assertEquals(expectedList, actualList);
  }
Esempio n. 13
0
  @Test
  /* Structural Basis, Data Flow */
  public void testSegmentPunctuation() throws IOException {
    /*
     * This test file should only go through the first if-statement and not the inner if.
     * Therefore each piece of punctuation should have its own token and this is independent of
     * the tokenLength.
     */
    Random rand = new Random();
    // Get a random integer between 1 and Integer.MAX_VALUE for the tokenLength.
    int tokenLength = rand.nextInt(Integer.MAX_VALUE) + 1;
    Segmentator segmentator = new Segmentator(tokenLength, "punctuation.txt");
    List<String> actualList = segmentator.segmentString();
    List<String> expectedList = new ArrayList<String>();
    expectedList.add(".");
    expectedList.add(",");
    expectedList.add("!");
    expectedList.add("?");

    assertEquals(expectedList, actualList);
  }
Esempio n. 14
0
 @Test
 /* Stress Test */
 public void testSegmentStringStress() {
   Segmentator segmentator = new Segmentator(5, "Frankenstein.txt");
   segmentator.compression();
 }