<commit_before>package uk.ac.ebi.atlas.model;

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

import java.util.Iterator;
import java.util.NoSuchElementException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class GeneProfileTest {

    private GeneProfile subject;

    private Expression expression1 = new Expression(new ExperimentRun("RUN_ACCESSION_1"), 2.2D);
    private Expression expression2 = new Expression(new ExperimentRun("RUN_ACCESSION_2"), 3D);

    @Before
    public void setUp() throws Exception {
        subject = GeneProfile.forGeneId("EMBL-1")
                    .addExpression(expression1)
                    .addExpression(expression2)
                    .create();
    }

    @Test
    public void testGetGeneSpecificity() throws Exception {
        assertThat(subject.getGeneSpecificity(), is(2));
    }

    @Test
    public void iteratorReturnsExpressionsAndThenNull() throws Exception {
        //given
        Iterator<GeneExpression> profileIterator = subject.iterator();

        //then
        assertThat(profileIterator.next().getLevel(), isOneOf(2.2D, 3D));
        assertThat(profileIterator.next().getLevel(), isOneOf(2.2D, 3D));
        //and
        assertThat(profileIterator.hasNext(), is(false));
    }

    @Test
    public void builderAddExpressionTest() {
        //given
        GeneProfile.Builder builder = GeneProfile.forGeneId("ENS1");
        builder.withCutoff(3D);

        Expression expressionSmaller = new Expression(new ExperimentRun("RUN_ACCESSION_1"), 2.2D);
        builder.addExpression(expressionSmaller);

        Expression expressionEquals = new Expression(new ExperimentRun("RUN_ACCESSION_2"), 3D);
        builder.addExpression(expressionEquals);

        Expression expressionBigger = new Expression(new ExperimentRun("RUN_ACCESSION_3"), 4D);
        builder.addExpression(expressionBigger);

        //when
        Iterator<GeneExpression> profileIterator = builder.create().iterator();

        //then
        assertThat(profileIterator.next().getLevel(), is(4D));
        //and
        assertThat(profileIterator.hasNext(), is(false));

    }
}
<commit_msg>test driven refactoring<commit_after>package uk.ac.ebi.atlas.model;

import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;

import java.util.*;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class GeneProfileTest {

    private GeneProfile subject;

    private Expression expression1 = new Expression(new ExperimentRun("RUN_ACCESSION_1"), 2.2D);
    private Expression expression2 = new Expression(new ExperimentRun("RUN_ACCESSION_2", Sets.newHashSet(new FactorValue("organism part","trunk"))), 3D);

    @Before
    public void setUp() throws Exception {
        subject = GeneProfile.forGeneId("EMBL-1")
                    .addExpression(expression1)
                    .addExpression(expression2)
                    .create();
    }

    @Test
    public void testGetGeneSpecificity() throws Exception {
        assertThat(subject.getGeneSpecificity(), is(2));
    }

    @Test
    public void iteratorReturnsExpressionsAndThenNull() throws Exception {
        //given
        Iterator<GeneExpression> profileIterator = subject.iterator();

        //then
        assertThat(profileIterator.next().getLevel(), isOneOf(2.2D, 3D));
        assertThat(profileIterator.next().getLevel(), isOneOf(2.2D, 3D));
        //and
        assertThat(profileIterator.hasNext(), is(false));
    }

    @Test
    public void builderAddExpressionTest() {
        //given
        GeneProfile.Builder builder = GeneProfile.forGeneId("ENS1");
        builder.withCutoff(3D);

        Expression expressionSmaller = new Expression(new ExperimentRun("RUN_ACCESSION_1"), 2.2D);
        builder.addExpression(expressionSmaller);

        Expression expressionEquals = new Expression(new ExperimentRun("RUN_ACCESSION_2"), 3D);
        builder.addExpression(expressionEquals);

        Expression expressionBigger = new Expression(new ExperimentRun("RUN_ACCESSION_3"), 4D);
        builder.addExpression(expressionBigger);

        //when
        Iterator<GeneExpression> profileIterator = builder.create().iterator();

        //then
        assertThat(profileIterator.next().getLevel(), is(4D));
        //and
        assertThat(profileIterator.hasNext(), is(false));

    }

    @Test
    public void filterByOrganismPartsShouldRemoveExpressionsWithUnwontedFactorValues(){
        Set<String> organismParts = Sets.newHashSet("beack", "trunk");

        Iterable<GeneExpression> geneExpressions = subject.filterByOrganismParts(organismParts);

        for(GeneExpression expression: geneExpressions){
            assertThat(expression.getOrganismPart(), is(not("beack")));
            assertThat(expression.getOrganismPart(), is("trunk"));
        }
    }


    @Test
    public void filterByOrganismPartsShouldKeepAllExpressionsWhenNoOrganismPartIsSpecified(){
        Set<String> organismParts = Sets.newHashSet();

        Iterable<GeneExpression> geneExpressions = subject.filterByOrganismParts(organismParts);

        List<GeneExpression> filteredGeneExpressions = new ArrayList<GeneExpression>();

        for(GeneExpression geneExpression: geneExpressions){
            filteredGeneExpressions.add(geneExpression);
        }

        assertThat(filteredGeneExpressions.size(), is(2));

    }

}

{'fraction_non_alphanumeric': 0.1076923076923077, 'fraction_numerical': 0.010073260073260074, 'mean_word_length': 3.3375694996028593, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3400806', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1429, 'n_words': 273}