Uploaded image for project: 'OpenNLP'
  1. OpenNLP
  2. OPENNLP-1519

Modified 3 tests in opennlp-tools to handle any iteration order

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.3.2
    • None
    • None

    Description

      Three tests

      • `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`
      • `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase`
      • `opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals`

      The tests fail because in the `equals` method for comparing elements within a Set also handles the ordering of elements as well.

      The `entrySet` here is a HashSet which doesn't maintain a constant order as mentioned in the [Java_17_documentation]https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/HashSet.html.

      /opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java:95

      Encountered the following error messages:

      org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 1a]>
      at opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)

      org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1B, 1A]>
      at opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest.testEqualsDifferentCase(DictionaryAsSetCaseInsensitiveTest.java:142)

      org.opentest4j.AssertionFailedError: expected: <[1a, 1b]> but was: <[1b, 1a]>
      at opennlp.tools.dictionary.DictionaryAsSetCaseSensitiveTest.testEquals(DictionaryAsSetCaseInsensitiveTest.java:121)

       

      The solution involves updating the assert statements to validate the presence of all elements regardless of their order.

      REPRODUCE:

      ```

      mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -Dtest=opennlp.tools.dictionary.DictionaryAsSetCaseInsensitiveTest#testEquals

      ```

       Can I proceed and create PR ?

      Attachments

        Activity

          People

            Unassigned Unassigned
            sujithra Sujithra Rajan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: