You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ko...@apache.org on 2017/10/04 01:18:40 UTC

[opennlp] branch master updated: OPENNLP-1138: Add more tests to Span (#269)

This is an automated email from the ASF dual-hosted git repository.

koji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/master by this push:
     new f02f2e5  OPENNLP-1138: Add more tests to Span (#269)
f02f2e5 is described below

commit f02f2e54ac7d88a6b7ee620e45e1bba878c63a56
Author: Koji Sekiguchi <ko...@rondhuit.com>
AuthorDate: Wed Oct 4 10:18:38 2017 +0900

    OPENNLP-1138: Add more tests to Span (#269)
    
    Thanks everyone for reviewing this!
---
 .../src/main/java/opennlp/tools/util/Span.java     | 25 ++++++++------------
 .../src/test/java/opennlp/tools/util/SpanTest.java | 27 +++++++++++++++++++++-
 2 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
index a8b0030..733e461 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
@@ -38,24 +38,17 @@ public class Span implements Comparable<Span> {
    * @param type the type of the span
    */
   public Span(int s, int e, String type) {
-
-    if (s < 0) {
-      throw new IllegalArgumentException("start index must be zero or greater: " + s);
-    }
-    if (e < 0) {
-      throw new IllegalArgumentException("end index must be zero or greater: " + e);
-    }
-    if (s > e) {
-      throw new IllegalArgumentException("start index must not be larger than end index: "
-              + "start=" + s + ", end=" + e);
-    }
-
-    start = s;
-    end = e;
-    this.type = type;
-    this.prob = 0d;
+    this(s, e, type, 0d);
   }
 
+  /**
+   * Initializes a new Span Object.
+   *
+   * @param s start of span.
+   * @param e end of span, which is +1 more than the last element in the span.
+   * @param type the type of the span
+   * @param prob probability of span.
+   */
   public Span(int s, int e, String type, double prob) {
 
     if (s < 0) {
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/SpanTest.java b/opennlp-tools/src/test/java/opennlp/tools/util/SpanTest.java
index add94ed..d9a14eb 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/SpanTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/SpanTest.java
@@ -286,7 +286,8 @@ public class SpanTest {
    */
   @Test
   public void testToString() {
-    new Span(50, 100).toString();
+    Assert.assertEquals("[50..100)", new Span(50, 100).toString());
+    Assert.assertEquals("[50..100) myType", new Span(50, 100, "myType").toString());
   }
 
   @Test
@@ -302,4 +303,28 @@ public class SpanTest {
     Span span1 = new Span(0, string1.length());
     Assert.assertEquals("", span1.trim(string1).getCoveredText(string1));
   }
+
+  /**
+   * Test if it fails to construct span with invalid start
+   */
+  @Test(expected = IllegalArgumentException.class)
+  public void testTooSmallStart() throws Exception {
+    new Span(-1, 100);
+  }
+
+  /**
+   * Test if it fails to construct span with invalid end
+   */
+  @Test(expected = IllegalArgumentException.class)
+  public void testTooSmallEnd() throws Exception {
+    new Span(50, -1);
+  }
+
+  /**
+   * Test if it fails to construct span with start > end
+   */
+  @Test(expected = IllegalArgumentException.class)
+  public void testStartLargerThanEnd() throws Exception {
+    new Span(100, 50);
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@opennlp.apache.org" <co...@opennlp.apache.org>'].