alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (LabelsSourceTest.java)

This example Java source code file (LabelsSourceTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

exception, label0, label1, label2, labelssource, labelssourcetest, list, sentence_, sentence_0, sentence_1, sentence_2, sentence_3, sentence_4, test, util

The LabelsSourceTest.java Java example source code

package org.deeplearning4j.text.documentiterator;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created by raver on 26.11.2015.
 */
public class LabelsSourceTest {

    @Before
    public void setUp() throws Exception {

    }

    @Test
    public void testNextLabel1() throws Exception {
        LabelsSource generator = new LabelsSource("SENTENCE_");

        assertEquals("SENTENCE_0", generator.nextLabel());
    }

    @Test
    public void testNextLabel2() throws Exception {
        LabelsSource generator = new LabelsSource("SENTENCE_%d_HAHA");

        assertEquals("SENTENCE_0_HAHA", generator.nextLabel());
    }

    @Test
    public void testNextLabel3() throws Exception {
        List<String> list = Arrays.asList("LABEL0", "LABEL1", "LABEL2");
        LabelsSource generator = new LabelsSource(list);

        assertEquals("LABEL0", generator.nextLabel());
    }

    @Test
    public void testLabelsCount1() throws Exception {
        List<String> list = Arrays.asList("LABEL0", "LABEL1", "LABEL2");
        LabelsSource generator = new LabelsSource(list);

        assertEquals("LABEL0", generator.nextLabel());
        assertEquals("LABEL1", generator.nextLabel());
        assertEquals("LABEL2", generator.nextLabel());

        assertEquals(3, generator.getNumberOfLabelsUsed());
    }

    @Test
    public void testLabelsCount2() throws Exception {
        LabelsSource generator = new LabelsSource("SENTENCE_");

        assertEquals("SENTENCE_0", generator.nextLabel());
        assertEquals("SENTENCE_1", generator.nextLabel());
        assertEquals("SENTENCE_2", generator.nextLabel());
        assertEquals("SENTENCE_3", generator.nextLabel());
        assertEquals("SENTENCE_4", generator.nextLabel());

        assertEquals(5, generator.getNumberOfLabelsUsed());
    }

    @Test
    public void testLabelsCount3() throws Exception {
        LabelsSource generator = new LabelsSource("SENTENCE_");

        assertEquals("SENTENCE_0", generator.nextLabel());
        assertEquals("SENTENCE_1", generator.nextLabel());
        assertEquals("SENTENCE_2", generator.nextLabel());
        assertEquals("SENTENCE_3", generator.nextLabel());
        assertEquals("SENTENCE_4", generator.nextLabel());

        assertEquals(5, generator.getNumberOfLabelsUsed());

        generator.reset();

        assertEquals(5, generator.getNumberOfLabelsUsed());
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java LabelsSourceTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.