<commit_before>package com.transgressoft.randomfilecopier.test;

import com.transgressoft.randomfilecopier.*;
import org.junit.*;
import org.junit.rules.*;

import java.io.*;
import java.util.*;
import java.util.stream.*;

import static org.junit.Assert.*;

/**
 * @author <NAME>
 * @version 0.2.3
 */
public class RandomFileCopierTest {

	String tenTestFilesFolder = "test-resources/10testfiles/";
	String testFolderPath;

    @Rule
    public TemporaryFolder testFolder = new TemporaryFolder();

	File sourceFolderFile = new File(tenTestFilesFolder);
	File[] sourceFiles = sourceFolderFile.listFiles();
	File[] destinationFiles;
	RandomFileCopier randomFileCopier;

	@Before
	public void setUp() {
		testFolderPath = testFolder.getRoot().getAbsolutePath();
	}

	@After
	public void tearDown() {
		testFolder.delete();
	}

	@Test
	public void setMaxBytesToCopySmallerThanDestinationSpace() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		long maxBytesInDestination = testFolder.getRoot().getUsableSpace() - 1;

		randomFileCopier.setMaxBytesToCopy(maxBytesInDestination);

		assertEquals(maxBytesInDestination, randomFileCopier.getMaxBytesToCopy());
	}

	@Test
	public void setMaxBytesToCopyGreaterThanDestinationSpace() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		long maxBytesInDestination = testFolder.getRoot().getUsableSpace();

		randomFileCopier.setMaxBytesToCopy(maxBytesInDestination + 1);

		assertEquals(maxBytesInDestination, randomFileCopier.getMaxBytesToCopy());
	}

	@Test
	public void filterExtensionsAreTheSame() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		String[] extensions = new String[]{"mp3", "m4a", "txt", "java"};

		randomFileCopier.setFilterExtensions(extensions);

		assertTrue(extensions.equals(randomFileCopier.getFilterExtensions()));
	}

	@Test
	public void copyWithGivenPrintStreamVerboseIsCorrect() throws Exception {
		File logFile = testFolder.newFile("log.txt");
		PrintStream printStream = new PrintStream(logFile);
		sourceFiles = sourceFolderFile.listFiles();
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0, printStream);
		randomFileCopier.setVerbose(true);
		randomFileCopier.randomCopy();

		Scanner logScanner = new Scanner(logFile);
		String scanningSourceLine = logScanner.nextLine();
		String filesFoundLine = logScanner.nextLine();
		String copyingFilesLine = logScanner.nextLine();

		int numCopiedFilesPos = filesFoundLine.indexOf(' ');
		int numCopiedFiles = Integer.parseInt(filesFoundLine.substring(0, numCopiedFilesPos));
		int numCopiedFilesPrint;
		for(numCopiedFilesPrint = 0; numCopiedFilesPrint < numCopiedFiles; numCopiedFilesPrint++) {
			logScanner.nextLine();
		}

		String doneLine = logScanner.nextLine();
		logScanner.close();
		assertTrue(logFile.delete());
		destinationFiles = testFolder.getRoot().listFiles();

		assertEquals(10, destinationFiles.length);
		assertEquals(10, numCopiedFiles);
		assertEquals(10, numCopiedFilesPrint);
		assertEquals("Scanning source directory...", scanningSourceLine);
		assertTrue(filesFoundLine.matches("\\d{1,} files found"));
		assertEquals("Copying files to the destination directory...", copyingFilesLine);
		assertTrue(doneLine.matches("Done. \\d+,?\\d* \\w+ copied"));
	}

	@Test
	public void copyAllFilesLimitingTheNumber() throws Exception {
		int maxFilesToCopy = 5;
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 5);
		randomFileCopier.randomCopy();

		destinationFiles = testFolder.getRoot().listFiles();
		assertTrue(maxFilesToCopy >= destinationFiles.length);
	}

	@Test
	public void copyAllFilesRegardingHalfBytesOfSources() throws Exception {<commit_msg>Quick fix<commit_after>package com.transgressoft.randomfilecopier.test;

import com.transgressoft.randomfilecopier.*;
import org.junit.*;
import org.junit.rules.*;

import java.io.*;
import java.util.*;
import java.util.stream.*;

import static org.junit.Assert.*;

/**
 * @author <NAME>
 * @version 0.2.3
 */
public class RandomFileCopierTest {

	String tenTestFilesFolder = "test-resources/10testfiles/";
	String testFolderPath;

    @Rule
    public TemporaryFolder testFolder = new TemporaryFolder();

	File sourceFolderFile = new File(tenTestFilesFolder);
	File[] sourceFiles = sourceFolderFile.listFiles();
	File[] destinationFiles;
	RandomFileCopier randomFileCopier;

	@Before
	public void setUp() {
		testFolderPath = testFolder.getRoot().getAbsolutePath();
	}

	@After
	public void tearDown() {
		testFolder.delete();
	}

	@Test
	public void setMaxBytesToCopySmallerThanDestinationSpace() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		long maxBytesInDestination = testFolder.getRoot().getUsableSpace() - 1;

		randomFileCopier.setMaxBytesToCopy(maxBytesInDestination);

		assertEquals(maxBytesInDestination, randomFileCopier.getMaxBytesToCopy());
	}

	@Test
	public void setMaxBytesToCopyGreaterThanDestinationSpace() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		long maxBytesInDestination = testFolder.getRoot().getUsableSpace();

		randomFileCopier.setMaxBytesToCopy(maxBytesInDestination + 1);

		assertEquals(maxBytesInDestination, randomFileCopier.getMaxBytesToCopy());
	}

	@Test
	public void filterExtensionsAreTheSame() throws Exception {
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0);
		String[] extensions = new String[]{"mp3", "m4a", "txt", "java"};

		randomFileCopier.setFilterExtensions(extensions);

		assertTrue(extensions.equals(randomFileCopier.getFilterExtensions()));
	}

	@Test
	public void copyWithGivenPrintStreamVerboseIsCorrect() throws Exception {
		File logFile = testFolder.newFile("log.txt");
		PrintStream printStream = new PrintStream(logFile);
		sourceFiles = sourceFolderFile.listFiles();
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 0, printStream);
		randomFileCopier.setVerbose(true);
		randomFileCopier.randomCopy();

		Scanner logScanner = new Scanner(logFile);
		String scanningSourceLine = logScanner.nextLine();
		String filesFoundLine = logScanner.nextLine();
		String copyingFilesLine = logScanner.nextLine();

		int numCopiedFilesPos = filesFoundLine.indexOf(' ');
		int numCopiedFiles = Integer.parseInt(filesFoundLine.substring(0, numCopiedFilesPos));
		int numCopiedFilesPrint;
		for(numCopiedFilesPrint = 0; numCopiedFilesPrint < numCopiedFiles; numCopiedFilesPrint++) {
			logScanner.nextLine();
		}

		String doneLine = logScanner.nextLine();
		logScanner.close();
		assertTrue(logFile.delete());
		destinationFiles = testFolder.getRoot().listFiles();

		assertEquals(10, destinationFiles.length);
		assertEquals(10, numCopiedFiles);
		assertEquals(10, numCopiedFilesPrint);
		assertEquals("Scanning source directory...", scanningSourceLine);
		assertTrue(filesFoundLine.matches("\\d{1,} files found"));
		assertEquals("Copying files to the destination directory...", copyingFilesLine);
		assertTrue(doneLine.matches("Done. \\d+.?\\d* \\w+ copied"));
	}

	@Test
	public void copyAllFilesLimitingTheNumber() throws Exception {
		int maxFilesToCopy = 5;
		randomFileCopier = new RandomFileCopier(tenTestFilesFolder, testFolderPath, 5);
		randomFileCopier.randomCopy();

		destinationFiles = testFolder.getRoot().listFiles();
		assertTrue(maxFilesToCopy >= destinationFiles.length);
	}

	@Test
	public void copyAllFilesRegardingHalfBytesOfSources() throws Exception {
{'fraction_non_alphanumeric': 0.10947755316355999, 'fraction_numerical': 0.006300866369125755, 'mean_word_length': 6.3756050338818975, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1794136', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2233, 'n_words': 441}