private void compareBinaryFolder(String path, boolean res) throws BrutException, IOException {

    String tmp = "";
    if (res) {
      tmp = File.separatorChar + "res" + File.separatorChar;
    }

    Files.walkFileTree(
        Paths.get(sTestOrigDir.toPath() + tmp + path),
        new SimpleFileVisitor<Path>() {

          @Override
          public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
              throws IOException {

            // hacky fix - load test by changing name of control
            File control = file.toFile();
            File test = new File(file.toString().replace("testapp-orig", "testapp-new"));

            if (test.isFile()) {
              if (control.hashCode() != test.hashCode()) {
                sResult = false;
                return FileVisitResult.TERMINATE;
              }
            } else {
              sResult = false;
              return FileVisitResult.TERMINATE;
            }
            return FileVisitResult.CONTINUE;
          }
        });
  }
  @BeforeClass
  public static void findDependencies() throws Exception {
    Path path = Paths.get("target/classes");
    Archive archive = new Archive(path, ClassFileReader.newInstance(path)) {};
    Finder finder = Dependencies.getClassDependencyFinder();

    archive
        .reader()
        .getClassFiles()
        .forEach(
            classFile ->
                StreamSupport.stream(finder.findDependencies(classFile).spliterator(), false)
                    .filter(dependency -> !isAnnotation(dependency))
                    .filter(dependency -> !self(dependency))
                    .forEach(
                        dependency ->
                            packageDependencies
                                .computeIfAbsent(
                                    dependency.getOrigin().getPackageName(), key -> new TreeSet<>())
                                .add(dependency.getTarget().getPackageName())));
  }
Example #3
0
  public PalindromeTest() {
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> palis;

    try {
      for (String line : Files.readAllLines(Paths.get("com/jsanders/web2"))) {
        words.add(line);
      }
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }

    palis = Palindrome.palindromes(words);
    assertEquals(palis.size(), 161, 0.01);

    int shortest = Word.shortestLength(words);
    assertEquals(shortest, 1, 0.01);

    int longest = Word.longestLength(words);
    assertEquals(longest, 24, 0.01);

    ArrayList<String> shortestWords = Word.shortestWords(words);
    assertEquals(shortestWords.size(), 52, 0.01);

    ArrayList<String> longestWords = Word.longestWords(words);
    assertEquals(longestWords.size(), 5, 0.01);

    int totalWords = Word.totalWords(words);
    double avgLen = Word.averageLength(words);

    assertEquals(totalWords, 235886, 0.01);
    assertEquals(avgLen, 9.56, 0.01);

    ArrayList<Double> letterFreq = Word.letterFrequency(words);
    assertEquals(letterFreq.get(0), 0.087, 0.01);

    double properFreq = Word.properFrequency(words);
    assertEquals(properFreq, 0.106, 0.01);

    ArrayList<Integer> startFreq = Word.startFrequency(words);
    assertEquals(startFreq.get(0), 17096, 0.01);

    ArrayList<String> sameStartEnd = Word.startEndWords(words);
    assertEquals(sameStartEnd.size(), 11505, 0.01);

    try {
      PrintWriter f = new PrintWriter("short.txt");
      for (String w : shortestWords) f.println(w);
      f.close();

      f = new PrintWriter("long.txt");
      for (String w : longestWords) f.println(w);
      f.close();

      f = new PrintWriter("same.txt");
      for (String w : sameStartEnd) f.println(w);
      f.close();

      f = new PrintWriter("statistics.txt");
      f.println("avg word len: " + avgLen);
      f.println("freq of letters: " + letterFreq);
      f.println("freq of proper nouns/names: " + properFreq);
      f.println("words that start with each letter:: " + startFreq);

      f.close();
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }
  }