You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/09/15 13:31:36 UTC

[10/13] incubator-joshua git commit: Moved regression test decoder/too-long to unit test. Removed resources as they are no longer needed.

Moved regression test decoder/too-long to unit test. Removed resources as they are no longer needed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/17ecec13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/17ecec13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/17ecec13

Branch: refs/heads/master
Commit: 17ecec13e942e08855074611df5c9d36cb5b57d7
Parents: 32f2753
Author: Michael A. Hedderich <mi...@users.noreply.github.com>
Authored: Thu Sep 15 12:53:58 2016 +0200
Committer: Michael A. Hedderich <mi...@users.noreply.github.com>
Committed: Thu Sep 15 14:21:05 2016 +0200

----------------------------------------------------------------------
 .../apache/joshua/decoder/cky/TooLongTest.java  | 68 ++++++++++++++++++++
 src/test/resources/decoder/too-long/output.gold |  4 --
 src/test/resources/decoder/too-long/test.sh     | 36 -----------
 3 files changed, 68 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/17ecec13/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java b/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java
new file mode 100644
index 0000000..b7c22f6
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java
@@ -0,0 +1,68 @@
+package org.apache.joshua.decoder.cky;
+
+import static org.apache.joshua.decoder.cky.TestUtil.translate;
+import static org.testng.Assert.assertEquals;
+
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Ensures that the decoder trims inputs when and only when it should
+ */
+public class TooLongTest {
+  private static final String INPUT1 = "as kingfishers draw fire";
+  private static final String GOLD1 = "as kingfishers ||| tm_glue_0=2.000 ||| 0.000";
+  private static final String INPUT2 = "dragonflies draw flame";
+  private static final String GOLD2 = "dragonflies ||| tm_glue_0=1.000 ||| 0.000";
+  private static final String INPUT3 = "(((as tumbled over rim in roundy wells stones ring";
+  private static final String GOLD3 = "(((as tumbled over rim in roundy wells stones ||| tm_glue_0=8.000 ||| 0.000";
+  private static final String INPUT4 = "(((like each tucked string tells";
+  private static final String GOLD4 = "|||  ||| 0.000";
+
+  private JoshuaConfiguration joshuaConfig;
+  private Decoder decoder;
+
+  @Test
+  public void givenInput_whenMaxLen2_thenOutputCorrect() throws Exception {
+    setUp(2, false);
+    String output = translate(INPUT1, decoder, joshuaConfig);
+    assertEquals(output.trim(), GOLD1);
+  }
+
+  @Test
+  public void givenInput_whenMaxLen1AndLatticeDecoding_thenOutputCorrect() throws Exception {
+    setUp(1, true);
+    String output = translate(INPUT2, decoder, joshuaConfig);
+    assertEquals(output.trim(), GOLD2);
+  }
+
+  @Test
+  public void givenInput_whenMaxLen8_thenOutputCorrect() throws Exception {
+    setUp(8, false);
+    String output = translate(INPUT3, decoder, joshuaConfig);
+    assertEquals(output.trim(), GOLD3);
+  }
+
+  @Test
+  public void givenInput_whenMaxLen3AndLatticeDecoding_thenOutputCorrect() throws Exception {
+    setUp(3, true);
+    String output = translate(INPUT4, decoder, joshuaConfig);
+    assertEquals(output.trim(), GOLD4);
+  }
+
+  public void setUp(int maxLen, boolean latticeDecoding) throws Exception {
+    joshuaConfig = new JoshuaConfiguration();
+    joshuaConfig.outputFormat = "%s ||| %f ||| %c";
+    joshuaConfig.maxlen = maxLen;
+    joshuaConfig.lattice_decoding = latticeDecoding;
+    decoder = new Decoder(joshuaConfig, "");
+  }
+
+  @AfterMethod
+  public void tearDown() throws Exception {
+    decoder.cleanUp();
+    decoder = null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/17ecec13/src/test/resources/decoder/too-long/output.gold
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/too-long/output.gold b/src/test/resources/decoder/too-long/output.gold
deleted file mode 100644
index 8773765..0000000
--- a/src/test/resources/decoder/too-long/output.gold
+++ /dev/null
@@ -1,4 +0,0 @@
-0 ||| as kingfishers ||| tm_glue_0=2.000 ||| 0.000
-0 ||| dragonflies ||| tm_glue_0=1.000 ||| 0.000
-0 ||| (((as tumbled over rim in roundy wells stones ||| tm_glue_0=8.000 ||| 0.000
-0 |||  |||  ||| 0.000

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/17ecec13/src/test/resources/decoder/too-long/test.sh
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/too-long/test.sh b/src/test/resources/decoder/too-long/test.sh
deleted file mode 100755
index 9491fd7..0000000
--- a/src/test/resources/decoder/too-long/test.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-set -u
-
-# Ensures that the decoder trims inputs when and only when it should
-
-(
-echo as kingfishers draw fire | $JOSHUA/bin/joshua -maxlen 2
-echo dragonflies draw flame | $JOSHUA/bin/joshua -maxlen 1 -lattice-decoding
-echo "(((as tumbled over rim in roundy wells stones ring" | $JOSHUA/bin/joshua -maxlen 8
-echo "(((like each tucked string tells" | $JOSHUA/bin/joshua -maxlen 3 -lattice-decoding
-) > output 2> log
-
-diff -u output output.gold > diff
-
-if [ $? -eq 0 ]; then
-    rm -f log output diff
-    exit 0
-else
-    exit 1
-fi