updated test. I'm not sure I like the long parameter names (search_algorithm, maximum_sentence_length). It's good for descriptiveness but hopefully this will be self-documenting. Typing that is a bit of a pain on the command line...
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/a4667737 Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/a4667737 Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/a4667737 Branch: refs/heads/7_confsystem Commit: a46677372de9e1f161afb5cb101aa5fb6e07a434 Parents: c762e4e Author: Matt Post <p...@cs.jhu.edu> Authored: Sat Sep 17 19:57:10 2016 +0200 Committer: Matt Post <p...@cs.jhu.edu> Committed: Sat Sep 17 22:06:18 2016 +0200 ---------------------------------------------------------------------- .../apache/joshua/decoder/cky/TooLongTest.java | 59 +++++++++----------- .../test/resources/decoder/too-long/output.gold | 4 -- .../src/test/resources/decoder/too-long/test.sh | 36 ------------ 3 files changed, 27 insertions(+), 72 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/a4667737/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java index ad7fb11..764800a 100644 --- a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java +++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TooLongTest.java @@ -21,11 +21,17 @@ package org.apache.joshua.decoder.cky; import static org.apache.joshua.decoder.cky.TestUtil.translate; import static org.testng.Assert.assertEquals; +import static com.typesafe.config.ConfigFactory.parseResources; +import static com.typesafe.config.ConfigValueFactory.fromAnyRef; + import org.apache.joshua.decoder.Decoder; -import org.apache.joshua.decoder.JoshuaConfiguration; import org.testng.annotations.AfterMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigValueFactory; + /** * Ensures that the decoder trims inputs when and only when it should */ @@ -39,43 +45,32 @@ public class TooLongTest { 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); + + @DataProvider(name = "params") + public Object[][] lmFiles() { + return new Object[][]{ + {INPUT1, 2, false, GOLD1}, + {INPUT2, 1, true, GOLD2}, + {INPUT3, 8, false, GOLD3}, + {INPUT4, 3, true, GOLD4} + }; } - @Test - public void givenInput_whenMaxLen1AndLatticeDecoding_thenOutputCorrect() throws Exception { - setUp(1, true); - String output = translate(INPUT2, decoder, joshuaConfig); - assertEquals(output.trim(), GOLD2); + @Test(dataProvider = "params") + public void producesCorrectOutput(String input, int maxlen, boolean latticeDecoding, String gold) throws Exception { + setUp(maxlen, latticeDecoding); + String output = translate(input, decoder); + assertEquals(output.trim(), gold); } - @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); - } + private void setUp(int maxLen, boolean latticeDecoding) throws Exception { + Config config = Decoder.getDefaultFlags() + .withValue("output_format", ConfigValueFactory.fromAnyRef("%s ||| %f ||| %c")) + .withValue("maximum_sentence_length", ConfigValueFactory.fromAnyRef(maxLen)) + .withValue("lattice_decoding", ConfigValueFactory.fromAnyRef(latticeDecoding)); - 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); + decoder = new Decoder(config); } @AfterMethod http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/a4667737/joshua-core/src/test/resources/decoder/too-long/output.gold ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/too-long/output.gold b/joshua-core/src/test/resources/decoder/too-long/output.gold deleted file mode 100644 index 8773765..0000000 --- a/joshua-core/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/a4667737/joshua-core/src/test/resources/decoder/too-long/test.sh ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/too-long/test.sh b/joshua-core/src/test/resources/decoder/too-long/test.sh deleted file mode 100755 index 9491fd7..0000000 --- a/joshua-core/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