<commit_before>package com.microsoft.tang;

import static org.junit.Assert.*;

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

import com.microsoft.tang.annotations.Name;
import com.microsoft.tang.annotations.NamedParameter;
import com.microsoft.tang.exceptions.BindException;
import com.microsoft.tang.exceptions.InjectionException;

public class TestNamedParameterRoundTrip {

    @NamedParameter()
    public final class Dimensionality implements Name<Integer> {
        // Intentionally Empty
    }

    /**
     * Break criterion for the optimizer. If the progress in mean loss between
     * two iterations is less than this, the optimization stops.
     */
    @NamedParameter()
    public final class Eps implements Name<Double> {
        // Intentionally Empty
    }

    @Test
    public void testRoundTrip() throws BindException, InjectionException {
        final int d = 10;
        final double eps = 1e-5;
        final ConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder();
        b.bindNamedParameter(Dimensionality.class, String.valueOf(d));
        b.bindNamedParameter(Eps.class, String.valueOf(eps));
        final Configuration conf = b.build();

        {
            final Injector i = Tang.Factory.getTang().newInjector(conf);

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }
        {
            final Injector i = Tang.Factory.getTang().newInjector(Utils.roundtrip(conf));

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }

    }

}<commit_msg>medium changes<commit_after>package com.microsoft.tang;

import static org.junit.Assert.*;

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

import com.microsoft.tang.annotations.Name;
import com.microsoft.tang.annotations.NamedParameter;
import com.microsoft.tang.exceptions.BindException;
import com.microsoft.tang.exceptions.InjectionException;

public class TestNamedParameterRoundTrip {

    @NamedParameter()
    public final class Dimensionality implements Name<Integer> {
        // Intentionally Empty
    }

    /**
     * Break criterion for the optimizer. If the progress in mean loss between
     * two iterations is less than this, the optimization stops.
     */
    @NamedParameter()
    public final class Eps implements Name<Double> {
        // Intentionally Empty
    }

    @Test
    public void testRoundTrip() throws BindException, InjectionException {
        final int d = 10;
        final double eps = 1e-5;
        final ConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder();
        b.bindNamedParameter(Dimensionality.class, String.valueOf(d));
        b.bindNamedParameter(Eps.class, String.valueOf(eps));
        final Configuration conf = b.build();

        {
            final Injector i = Tang.Factory.getTang().newInjector(conf);

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }
                
        
        {
            final Injector i = Tang.Factory.getTang().newInjector(Utils.roundtrip(conf));

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }
        
        {
            final Injector parent = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
            final Injector i = parent.createChildInjector(conf);

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }
        
        {
            final Injector parent = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
            final Injector i = parent.createChildInjector(Utils.roundtrip(conf));

            final int readD = i.getNamedParameter(Dimensionality.class).intValue();
            final double readEps = i.getNamedParameter(Eps.class).doubleValue();

            assertEquals(eps, readEps, 1e-12);
            assertEquals(d, readD);
        }

    }

}
{'fraction_non_alphanumeric': 0.10246406570841889, 'fraction_numerical': 0.0053388090349075976, 'mean_word_length': 2.7098248286367097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1117271', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1333, 'n_words': 287}