<commit_before>package sword.java.class_analyzer.code

import org.scalatest.FunSuite
import java.io.File
import java.util.HashSet
import sword.java.class_analyzer.ProjectAnalyzer
import sword.java.class_analyzer.ref.ClassReference
import sword.java.class_analyzer.ref.RootReference

class MissingInstructionsTest extends FunSuite {

  // It is expected to find the folder target/scala-XXX/classes with the
  // compiled classes where XXX depnds on the version of scala
  test("All instructions within the project are implemented") {
    var validClassPathCount = 0
    val targetFile = new File("target")
    targetFile.list.filter(_.startsWith("scala-")).foreach { classPathFolderName =>
      
      val compilationClassPathFile = new File(targetFile, classPathFolderName)
      if (compilationClassPathFile.list.contains("classes")) {
        val classPathFile = new File(compilationClassPathFile, "classes")
        validClassPathCount += 1

        val root = new RootReference
        val mainClass = root.addClass("sword.java.class_analyzer.ProjectAnalyzer")
        val notFound = new HashSet[ClassReference]
        val loadedClasses = ProjectAnalyzer.analyzeProject(mainClass, classPathFile, notFound)
        assert(loadedClasses.size > 0, "Not classes loaded on path " + classPathFile.getAbsolutePath)

        val iterator = loadedClasses.iterator
        while (iterator.hasNext) {
          val loaded = iterator.next
          loaded.methodTable.methods.foreach { method =>
            assert(method.isValid, method.getInvalidReason + " [ " +
                loaded.getReference.getQualifiedName + "." + method.name + " ] ")
          }
        }
      }
    }

    assert(validClassPathCount > 0, "No valid class paths found")
  }
}<commit_msg>Added test to ensure not unused code within methods.<commit_after>package sword.java.class_analyzer.code

import org.scalatest.FunSuite
import java.io.File
import java.util.HashSet
import sword.java.class_analyzer.ProjectAnalyzer
import sword.java.class_analyzer.ref.ClassReference
import sword.java.class_analyzer.ref.RootReference

class MissingInstructionsTest extends FunSuite {

  // It is expected to find the folder target/scala-XXX/classes with the
  // compiled classes where XXX depnds on the version of scala
  test("All instructions within the project are implemented") {
    var validClassPathCount = 0
    val targetFile = new File("target")
    targetFile.list.filter(_.startsWith("scala-")).foreach { classPathFolderName =>

      val compilationClassPathFile = new File(targetFile, classPathFolderName)
      if (compilationClassPathFile.list.contains("classes")) {
        val classPathFile = new File(compilationClassPathFile, "classes")
        validClassPathCount += 1

        val root = new RootReference
        val mainClass = root.addClass("sword.java.class_analyzer.ProjectAnalyzer")
        val notFound = new HashSet[ClassReference]
        val loadedClasses = ProjectAnalyzer.analyzeProject(mainClass, classPathFile, notFound)
        assert(loadedClasses.size > 0, "Not classes loaded on path " + classPathFile.getAbsolutePath)

        val iterator = loadedClasses.iterator
        while (iterator.hasNext) {
          val loaded = iterator.next
          loaded.methodTable.methods.foreach { method =>
            assert(method.isValid, method.getInvalidReason + " [ " +
                loaded.getReference.getQualifiedName + "." + method.name + " ] ")
          }
        }
      }
    }

    assert(validClassPathCount > 0, "No valid class paths found")
  }

  // This test assumes that the standard java compiler does not have any reason
  // to leave unused code within methods. If it is found it is assumed to be an
  // error in this project and should be fixed
  test("All code is referenced") {
    var validClassPathCount = 0
    val targetFile = new File("target")
    targetFile.list.filter(_.startsWith("scala-")).foreach { classPathFolderName =>

      val compilationClassPathFile = new File(targetFile, classPathFolderName)
      if (compilationClassPathFile.list.contains("classes")) {
        val classPathFile = new File(compilationClassPathFile, "classes")
        validClassPathCount += 1

        val root = new RootReference
        val mainClass = root.addClass("sword.java.class_analyzer.ProjectAnalyzer")
        val notFound = new HashSet[ClassReference]
        val loadedClasses = ProjectAnalyzer.analyzeProject(mainClass, classPathFile, notFound)
        assert(loadedClasses.size > 0, "Not classes loaded on path " + classPathFile.getAbsolutePath)

        val iterator = loadedClasses.iterator
        while (iterator.hasNext) {
          val loaded = iterator.next
          loaded.methodTable.methods.foreach { method =>
            val methodCode = method.getMethodCode
            if (methodCode != null) {
              assert(!methodCode.hasUnreferencedCode, "Found unreferenced code at method " +
                loaded.getReference.getQualifiedName + "." + method.name)
            }
          }
        }
      }
    }

    assert(validClassPathCount > 0, "No valid class paths found")
  }
}
{'fraction_non_alphanumeric': 0.08526829268292684, 'fraction_numerical': 0.0023414634146341463, 'mean_word_length': 3.153970826580227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5398419', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1342, 'n_words': 353}