import static org.junit.Assert.assertEquals; import java.util.ArrayList; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; /** * JUnit class for parameterized testing, see * https://github.com/junit-team/junit/wiki/Parameterized-tests * * @author Alexander Schaap * */ @RunWith(Parameterized.class) public class KWICTest { @Parameters @SuppressWarnings("unchecked") // casting storages public static Iterable data() { ArrayList result = new ArrayList(); StorageInterface[] lss = { new StorageObservableLinkedList>>(), new StorageObservableArrayList>>(), new StoragePassthrough>>() }; StorageInterface[] slss = { new StorageObservableLinkedList>>>(), new StorageObservableArrayList>>>(), new StoragePassthrough>>>() }; InputInterface[] inputs = { new Input<>(), new Input2<>() }; WordCommandInterface[] wcs = { new WordCommandString(), new WordCommandCharArray() }; AlphabetizerInterface[] alphas = { new AlphabetizerQuickSort<>(), new AlphabetizerStupidGnomeSort<>() }; CircularShifterInterface[] shifters = { new CircularShifter(), new CircularShifter2() }; OutputInterface[] outputs = { new Output(), new Output2() }; String filename = "../JavaKWIC/src/test.txt"; for (StorageInterface ls : lss) { for (StorageInterface sls : slss) { for (InputInterface input : inputs) { for (WordCommandInterface wc : wcs) { for (AlphabetizerInterface alpha : alphas) { for (CircularShifterInterface shift : shifters) { for (OutputInterface output : outputs) { StorageInterface>>> ssls; if (sls.equals(slss[2])) ssls = new StoragePassthrough>>>(); else ssls = (StorageInterface>>>) sls; result.add(new Object[] { new KWICRecord( (StorageInterface>>) ls, (StorageInterface>>>) sls, ssls, input, wc, shift, alpha, output, filename), "foot yawp, yawp foot\nblue zzzz mooo, mooo blue zzzz, zzzz mooo blue\n" }); } } } } } } } return result; } private KWICRecord input; private String expected; public KWICTest(KWICRecord input, String expected) { this.input = input; this.expected = expected; } /** * JUnit test trying a combination of implementations and checking the output. */ @Test public void test() { MasterControl kwic = new MasterControl(input); String configuration = kwic.config(); String actualResult = kwic.run(); assertEquals("KWIC config:\n" + configuration + "\nActual result:\n" + actualResult, expected, actualResult); input.ls.reset(); input.sls.reset(); input.ssls.reset(); input.output.reset(); } }