<commit_before>package com.alexrnl.subtitlecorrector.correctionstrategy;

import static com.alexrnl.subtitlecorrector.common.TranslationKeys.KEYS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Locale;

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

import com.alexrnl.subtitlecorrector.common.Subtitle;

/**
 * Test suite for the {@link FixPunctuation} class.
 * @author Alex
 */
public class FixPunctuationTest {
	/** The punctuation fixer strategy */
	private FixPunctuation		fixPunctuation;
	/** Reference to the locale parameter of the strategy */
	private Parameter<Locale>	locale;
	
	/**
	 * Set up test attributes.
	 * @throws URISyntaxException
	 *         if there is an issue when parsing the path.
	 * @throws IOException
	 *         if there is an issue when loading the rules.
	 */
	@Before
	public void setUp () throws IOException, URISyntaxException {
		fixPunctuation = new FixPunctuation(Paths.get(FixPunctuation.class.getResource("/punctuation").toURI()));
		locale = (Parameter<Locale>) fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale());
		assertNotNull(locale);
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameters()}.
	 */
	@Test
	public void testGetParameters () {
		assertEquals(1, fixPunctuation.getParameters().size());
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameterByName(String)}.
	 */
	@Test
	public void testGetParameterByName () {
		final Iterator<Parameter<?>> parametersIterator = fixPunctuation.getParameters().iterator();
		assertEquals(parametersIterator.next(), fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale()));
		assertNull(fixPunctuation.getParameterByName("ldr"));<commit_msg>Add a test case for the fix punctuation strategy<commit_after>package com.alexrnl.subtitlecorrector.correctionstrategy;

import static com.alexrnl.subtitlecorrector.common.TranslationKeys.KEYS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Locale;

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

import com.alexrnl.subtitlecorrector.common.Subtitle;

/**
 * Test suite for the {@link FixPunctuation} class.
 * @author Alex
 */
public class FixPunctuationTest {
	/** The punctuation fixer strategy */
	private FixPunctuation		fixPunctuation;
	/** Reference to the locale parameter of the strategy */
	private Parameter<Locale>	locale;
	
	/**
	 * Set up test attributes.
	 * @throws URISyntaxException
	 *         if there is an issue when parsing the path.
	 * @throws IOException
	 *         if there is an issue when loading the rules.
	 */
	@Before
	public void setUp () throws IOException, URISyntaxException {
		fixPunctuation = new FixPunctuation(Paths.get(FixPunctuation.class.getResource("/punctuation").toURI()));
		locale = (Parameter<Locale>) fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale());
		assertNotNull(locale);
	}
	
	/**
	 * Check that the strategy cannot be created with a file as a parameter.
	 * @throws IOException
	 *         if there is an issue when loading the rules.
	 */
	@SuppressWarnings("unused")
	@Test(expected = IllegalArgumentException.class)
	public void createWithFile () throws IOException {
		final Path tempFile = Files.createTempFile("punctuationRule", "txt");
		tempFile.toFile().deleteOnExit();
		new FixPunctuation(tempFile);
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameters()}.
	 */
	@Test
	public void testGetParameters () {
		assertEquals(1, fixPunctuation.getParameters().size());
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameterByName(String)}.
	 */
	@Test
	public void testGetParameterByName () {
		final Iterator<Parameter<?>> parametersIterator = fixPunctuation.getParameters().iterator();
		assertEquals(parametersIterator.next(), fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale()));
		assertNull(fixPunctuation.getParameterByName("ldr"));
{'fraction_non_alphanumeric': 0.11369332421964001, 'fraction_numerical': 0.000455684666210982, 'mean_word_length': 5.013698630136986, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '263421', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1273, 'n_words': 306}