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

Improve WindowFeatureGeneratorTest

    XMLWordPrintableJSON

Details

    • Test
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 1.9.0
    • 1.9.1
    • None

    Description

      I'd like to improve WindowFeatureGeneratorTest from the following perspective:

      • testWindowSizeOne should check the contents of the returned features. It checks the length of the features only now
      • most of test methods uses Assert.assertEquals(expected, actual) in opposite way for its arguments when checking the contents of the returned features
      Assert.assertEquals(features.get(0), testSentence[testTokenIndex]);
      

      should be

      Assert.assertEquals(testSentence[testTokenIndex], features.get(0));
      
      • Though I pointed out the arguments in assertEquals() above, I think we'd better use exact concrete string rather than expression such like testSentence[testTokenIndex] for the expected. And also, testForCorrectFeatures uses contains method when checking the contents of the returned features but I think we should avoid using contains when checking the items in a List, rather than writing like this:
          Assert.assertTrue(features.contains(WindowFeatureGenerator.PREV_PREFIX + "2" +
              testSentence[testTokenIndex - 2]));
          Assert.assertTrue(features.contains(WindowFeatureGenerator.PREV_PREFIX + "1" +
              testSentence[testTokenIndex - 1]));
      
          Assert.assertTrue(features.contains(testSentence[testTokenIndex]));
      
          Assert.assertTrue(features.contains(WindowFeatureGenerator.NEXT_PREFIX + "1" +
              testSentence[testTokenIndex + 1]));
          Assert.assertTrue(features.contains(WindowFeatureGenerator.NEXT_PREFIX + "2" +
              testSentence[testTokenIndex + 2]));
      

      but I'd like to rewrite them like this:

          Assert.assertEquals("d",features.get(0));
          Assert.assertEquals("p1c",features.get(1));
          Assert.assertEquals("p2b",features.get(2));
          Assert.assertEquals("n1e",features.get(3));
          Assert.assertEquals("n2f",features.get(4));
      

      The second form helps us to understand how WindowFeatureGenerator works and it's easier to read.

      Attachments

        Issue Links

          Activity

            People

              koji Koji Sekiguchi
              koji Koji Sekiguchi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: