<commit_before><commit_msg>Add unit tests for MatchAccumulator.<commit_after>package com.mistraltech.smog.core;


import org.hamcrest.StringDescription;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

public class MatchAccumulatorTest
{
    private StringDescription mismatchDescription;

    @Before
    public void setUp() {
        mismatchDescription = new StringDescription();
    }

    @Test
    public void givesSuccessResultWhenNoResultSpecifiedAtConstructionAndNoMatchesFail() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription);

        assertTrue(matchAccumulator.result());
    }

    @Test
    public void givesSuccessResultWhenSucceedingAtConstructionAndNoMatchesFail() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription, true);

        assertTrue(matchAccumulator.result());
    }

    @Test
    public void givesFailureResultWhenFailingAtConstruction() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription, false);

        assertFalse(matchAccumulator.result());
    }

    @Test
    public void givesFailureResultWhenAnyMatchFails() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription);

        matchAccumulator.matches(equalTo("A"), "A");
        matchAccumulator.matches(equalTo("B"), "-");
        matchAccumulator.matches(equalTo("C"), "C");

        assertFalse(matchAccumulator.result());
    }

    @Test
    public void givesSuccessResultWhenAllMatchesSucceed() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription);

        matchAccumulator.matches(equalTo("A"), "A");
        matchAccumulator.matches(equalTo("B"), "B");
        matchAccumulator.matches(equalTo("C"), "C");

        assertTrue(matchAccumulator.result());
    }

    @Test
    public void doesNotUpdateMismatchDescriptionWhenMatchesSucceed() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription);

        matchAccumulator.matches(equalTo("A"), "A");
        matchAccumulator.matches(equalTo("B"), "B");
        matchAccumulator.matches(equalTo("C"), "C");

        assertEquals("", mismatchDescription.toString());
    }

    @Test
    public void updatesMismatchDescriptionForFailingMatches() {
        MatchAccumulator matchAccumulator = MatchAccumulator.matchAccumulator(mismatchDescription);

        matchAccumulator.matches(equalTo("A"), "a"); // mismatch
        matchAccumulator.matches(equalTo("B"), "B");
        matchAccumulator.matches(equalTo("C"), "c"); // mismatch
        matchAccumulator.matches(equalTo("D"), "d"); // mismatch
        matchAccumulator.matches(equalTo("E"), "E");

        String expectedMismatchDescription = "was \"a\""
            + MatchAccumulator.MISMATCH_CONJUNCTIVE_ADVERB
            + "was \"c\""
            + MatchAccumulator.MISMATCH_CONJUNCTIVE_ADVERB
            + "was \"d\"";

        assertEquals(expectedMismatchDescription, mismatchDescription.toString());
    }
}
{'fraction_non_alphanumeric': 0.1089824120603015, 'fraction_numerical': 0.0, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1890153', 'n_tokens_mistral': 921, 'n_tokens_neox': 890, 'n_words': 131}