Repository: opennlp Updated Branches: refs/heads/LangDetect 661e5a104 -> 5a234de70 (forced update)
OPENNLP-1027: Add tests for Event. The previous commit doean't have EventTest Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/d8cdd5ee Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/d8cdd5ee Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/d8cdd5ee Branch: refs/heads/LangDetect Commit: d8cdd5eeffe9b63949129d09f6b0c7ad2d517e90 Parents: 0733d7c Author: koji <k...@apache.org> Authored: Wed Apr 19 07:07:15 2017 +0900 Committer: koji <k...@apache.org> Committed: Wed Apr 19 07:07:15 2017 +0900 ---------------------------------------------------------------------- .../java/opennlp/tools/ml/model/EventTest.java | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/opennlp/blob/d8cdd5ee/opennlp-tools/src/test/java/opennlp/tools/ml/model/EventTest.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/model/EventTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/model/EventTest.java new file mode 100644 index 0000000..7400e9e --- /dev/null +++ b/opennlp-tools/src/test/java/opennlp/tools/ml/model/EventTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opennlp.tools.ml.model; + +import org.junit.Assert; +import org.junit.Test; + +public class EventTest { + + @Test + public void testNullOutcome() { + try { + new Event(null, new String[]{"aa", "bb", "cc"}); + Assert.fail("NPE must be thrown"); + } + catch (NullPointerException expected) { + } + } + + @Test + public void testNullContext() { + try { + new Event("o1", null); + Assert.fail("NPE must be thrown"); + } + catch (NullPointerException expected) { + } + } + + @Test + public void testWithValues() { + Event event = new Event("o1", + new String[]{"aa", "bb", "cc"}); + + Assert.assertEquals("o1", event.getOutcome()); + Assert.assertArrayEquals(new String[]{"aa", "bb", "cc"}, event.getContext()); + Assert.assertNull(event.getValues()); + Assert.assertEquals("o1 [aa bb cc]", event.toString()); + } + + @Test + public void testWithoutValues() { + Event event = new Event("o1", + new String[]{"aa", "bb", "cc"}, + new float[]{0.2F, 0.4F, 0.4F}); + + Assert.assertEquals("o1", event.getOutcome()); + Assert.assertArrayEquals(new String[]{"aa", "bb", "cc"}, event.getContext()); + Assert.assertArrayEquals(new float[]{0.2F, 0.4F, 0.4F}, event.getValues(), 0.001F); + Assert.assertEquals("o1 [aa=0.2 bb=0.4 cc=0.4]", event.toString()); + } +}