コード例 #1
0
 @Test
 public void shouldPrefixEveryElementInIteratorAndNothingMore() {
   Iterator<Integer> incrementing = generatorFactory.boundedIncrementing(0, 2, 10);
   Iterator<String> prefixing = generatorFactory.prefix(incrementing, "pre");
   assertThat(prefixing.next(), is("pre0"));
   assertThat(prefixing.next(), is("pre2"));
   assertThat(prefixing.next(), is("pre4"));
   assertThat(prefixing.next(), is("pre6"));
   assertThat(prefixing.next(), is("pre8"));
   assertThat(prefixing.next(), is("pre10"));
   assertThat(prefixing.hasNext(), is(false));
   assertThat(incrementing.hasNext(), is(false));
 }
 @Override
 public Iterator<List<String>> getGeneratorImpl(GeneratorFactory generatorFactory) {
   Tuple2<Double, String> p1 = Tuple.tuple2(1.0, "1");
   Tuple2<Double, String> p2 = Tuple.tuple2(1.0, "2");
   Tuple2<Double, String> p3 = Tuple.tuple2(1.0, "3");
   ArrayList<Tuple2<Double, String>> items = new ArrayList<Tuple2<Double, String>>();
   items.add(p1);
   items.add(p2);
   items.add(p3);
   Iterator<Integer> amountToRetrieveGenerator = generatorFactory.uniform(0, 3);
   Iterator<List<String>> generator =
       generatorFactory.weightedDiscreteList(items, amountToRetrieveGenerator);
   return generator;
 }
  @Test(expected = GeneratorException.class)
  public void emptyConstructorTest() {
    // Given
    GeneratorFactory generatorFactory = new GeneratorFactory(new RandomDataGeneratorFactory());
    Iterator<Integer> amountToRetrieveGenerator = generatorFactory.uniform(0, 3);
    ArrayList<Tuple2<Double, String>> emptyItems = new ArrayList<Tuple2<Double, String>>();
    Iterator<List<String>> generator =
        generatorFactory.weightedDiscreteList(emptyItems, amountToRetrieveGenerator);

    // When
    generator.next();

    // Then
    assertEquals("Empty DiscreteGenerator should throw exception on next()", false, true);
  }
コード例 #4
0
  @Test
  public void testCreationWihtSimpleDescriptor() throws Exception {
    InputStream generatorDescriptorIn =
        getClass()
            .getResourceAsStream("/opennlp/tools/util/featuregen/TestFeatureGeneratorConfig.xml");

    // If this fails the generator descriptor could not be found
    // at the expected location
    Assert.assertNotNull(generatorDescriptorIn);

    Collection<String> expectedGenerators = new ArrayList<String>();
    expectedGenerators.add(OutcomePriorFeatureGenerator.class.getName());

    AggregatedFeatureGenerator aggregatedGenerator =
        (AggregatedFeatureGenerator) GeneratorFactory.create(generatorDescriptorIn, null);

    for (AdaptiveFeatureGenerator generator : aggregatedGenerator.getGenerators()) {

      expectedGenerators.remove(generator.getClass().getName());

      // if of kind which requires parameters check that
    }

    // If this fails not all expected generators were found and
    // removed from the expected generators collection
    Assert.assertEquals(0, expectedGenerators.size());
  }
コード例 #5
0
  /**
   * Tests the creation from a descriptor which contains an unkown element. The creation should fail
   * with an {@link InvalidFormatException}
   */
  @Test(expected = IOException.class)
  public void testCreationWithUnkownElement() throws IOException {
    InputStream descIn =
        getClass()
            .getResourceAsStream(
                "/opennlp/tools/util/featuregen/FeatureGeneratorConfigWithUnkownElement.xml");

    try {
      GeneratorFactory.create(descIn, null);
    } finally {
      descIn.close();
    }
  }
コード例 #6
0
public class ExampleTest {

  @Rule
  public Generator<Tuple2<Integer, String>> tuples =
      GeneratorFactory.tuples(asList(1, 2, 3, 4), asList("a", "b", "c"));

  @Test
  public void testSomething() throws Exception {
    assertTrue(tuples.value()._1 % 2 == 0 || tuples.value()._2.length() > 2);
  }

  @Test
  public void throwingUp() {
    throw new RuntimeException();
  }
}
コード例 #7
0
  @Test
  public void testCreationWithCustomGenerator() throws Exception {
    InputStream generatorDescriptorIn =
        getClass().getResourceAsStream("/opennlp/tools/util/featuregen/CustomClassLoading.xml");

    // If this fails the generator descriptor could not be found
    // at the expected location
    Assert.assertNotNull(generatorDescriptorIn);

    AggregatedFeatureGenerator aggregatedGenerator =
        (AggregatedFeatureGenerator) GeneratorFactory.create(generatorDescriptorIn, null);

    Collection<AdaptiveFeatureGenerator> embeddedGenerator = aggregatedGenerator.getGenerators();

    Assert.assertEquals(1, embeddedGenerator.size());

    for (AdaptiveFeatureGenerator generator : embeddedGenerator) {
      Assert.assertEquals(TokenFeatureGenerator.class.getName(), generator.getClass().getName());
    }
  }