<commit_before>package com.github.quadflask.smartcrop;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by flask on 2015. 10. 27..
 */
public class SmartCropTest {

	static String samplePath = "src/test/resources/sample";
	static String debugPath = "src/test/resources/debug";

	static String[] sampleImages = {
			"29386679.jpg",
			"32872321.jpg",
			"65131509.jpg",
			"65158073.jpg",
			"65309527.jpg",
			"65334383.jpg",
			"65356729.jpg",
			"65438769.jpg",
			"goodtimes.jpg",
			"guitarist.jpg",
			"img.jpg",
			"kitty.jpg",};

	static BufferedImage[] bufferedImages = new BufferedImage[sampleImages.length];
	static BufferedImage[] resultBufferedImages = new BufferedImage[sampleImages.length];

	@BeforeClass
	public static void setup() throws Exception {
		for (int i = 0; i < sampleImages.length; i++) {
			String name = sampleImages[i];
			bufferedImages[i] = ImageIO.read(new File(samplePath, name));
		}
	}

	@AfterClass
	public static void teardown() {
		for (int i = 0; i < sampleImages.length; i++) {
			final String name = sampleImages[i];
			final BufferedImage resultBufferedImage = resultBufferedImages[i];

			new Thread(() -> {
				try {
					long b = System.currentTimeMillis();
					String newName = name; // name.replace("jpg", "png");
					ImageIO.write(resultBufferedImage, "jpg", new File(debugPath, newName));
					System.out.println("saved... " + newName + " / took " + (System.currentTimeMillis() - b) + "ms");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}).run();
		}
	}

	@Test
	public void test() throws Exception {
		long b;
		for (int i = 0; i < sampleImages.length; i++) {
			String name = sampleImages[i];
			BufferedImage img = bufferedImages[i];

			b = System.currentTimeMillis();
			Options options = new Options();
			options.setBufferedBitmapType(BufferedImage.TYPE_INT_RGB);
			CropResult result = new SmartCrop(options).analyze(img);
			System.out.println("done: " + name + " / analyze took " + (System.currentTimeMillis() - b) + "ms");

			resultBufferedImages[i] = result.getBufferedImage();
		}
	}
}<commit_msg>Refactor test more readable, flexible<commit_after>package com.github.quadflask.smartcrop;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Created by flask on 2015. 10. 27..
 */
public class SmartCropTest {

	static String samplePath = "src/test/resources/sample";
	static String debugPath = "src/test/resources/debug";

	static Map<String, BufferedImage> bufferedImages = new ConcurrentHashMap<>();
	static Map<String, BufferedImage> resultBufferedImages = new ConcurrentHashMap<>();

	@BeforeClass
	public static void setup() throws Exception {
		Arrays.stream(new File(samplePath)
				.listFiles(pathname -> pathname.getName().endsWith(".jpg")))
				.forEach(file -> {
					try {
						bufferedImages.put(file.getName(), ImageIO.read(file));
					} catch (IOException e) {
						e.printStackTrace();
					}
				});
	}

	@AfterClass
	public static void teardown() {
		resultBufferedImages.forEach((name, resultBufferedImage) -> {
			new Thread(() -> {
				try {
					long b = System.currentTimeMillis();
					String newName = name; // name.replace("jpg", "png");
					ImageIO.write(resultBufferedImage, "jpg", new File(debugPath, newName));
					System.out.println("saved... " + newName + " / took " + (System.currentTimeMillis() - b) + "ms");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}).run();
		});
	}

	@Test
	public void test() throws Exception {
		bufferedImages.forEach((name, img) -> {
			long b = System.currentTimeMillis();
			Options options = new Options();
			options.setBufferedBitmapType(BufferedImage.TYPE_INT_RGB);
			CropResult result = new SmartCrop(options).analyze(img);
			System.out.println("done: " + name + " / analyze took " + (System.currentTimeMillis() - b) + "ms");

			resultBufferedImages.put(name, result.getBufferedImage());
		});
	}
}
{'fraction_non_alphanumeric': 0.14468371467025573, 'fraction_numerical': 0.018618214445939883, 'mean_word_length': 3.9654788418708242, 'pattern_counts': {'":': 0, '<': 10, '<?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': '3227130', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1421, 'n_words': 316}