package com.gradesscope.photoeditor;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.junit.Test;

public class PictureTest_FillTables_Table {

	/*
	 * Check the contents of the "table" array generated from Micro.bmp
	 */
	@Test
	public void testFillTable_Micro() {
		Picture pic = Picture.loadPicture("Micro.bmp");
		int[][] computedArray = pic.getTableAfterFillTables();
		int[][] correctArray = { { 20, 60, 50, 90, 140 }, { 10, 30, 80, 90, 150 }, { 20, 70, 120, 100, 130 } };
		int width = computedArray.length;
		int height = computedArray[0].length;
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				assertEquals("Mistake at (" + x + "," + y + "):", correctArray[x][y], computedArray[x][y]);
			}
		}
	}

	/*
	 * Check the contents of the "table" array generated from Tiny.bmp
	 */
	@Test
	public void testFillTable_Tiny() {
		Picture pic = Picture.loadPicture("Tiny.bmp");
		int[][] computedArray = pic.getTableAfterFillTables();
		int[][] correctArray = { { 0, 7, 14, 14, 14, 14 }, { 0, 7, 7, 14, 14, 14 }, { 0, 7, 7, 14, 14, 7 },
				{ 0, 7, 7, 14, 7, 7 }, { 0, 7, 7, 0, 7, 14 }, { 0, 14, 0, 7, 7, 14 }, { 7, 0, 7, 7, 14, 14 },
				{ 7, 7, 7, 14, 21, 21 }, { 7, 7, 14, 21, 14, 14 }, { 7, 7, 14, 28, 21, 14 } };
		int width = computedArray.length;
		int height = computedArray[0].length;
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				assertEquals("Mistake at (" + x + "," + y + "):", correctArray[x][y], computedArray[x][y]);
			}
		}
	}

	/*
	 * Check the contents of the "table" array generated from Okinawa_tiny.bmp
	 */
	@Test
	public void testFillTable_Okinawa_Tiny() {
		Picture pic = Picture.loadPicture("Okinawa_tiny.bmp");
		int[][] computedArray = pic.getTableAfterFillTables();
		int[][] correctArray = { { 2, 116, 148, 181, 213, 227 }, { 6, 19, 164, 176, 207, 244 },
				{ 5, 20, 97, 148, 228, 274 }, { 4, 9, 12, 170, 201, 249 }, { 6, 8, 16, 84, 249, 246 },
				{ 6, 13, 16, 269, 102, 164 }, { 5, 15, 180, 45, 106, 170 }, { 8, 33, 155, 109, 122, 164 },
				{ 4, 96, 78, 108, 137, 146 }, { 8, 84, 126, 108, 130, 147 } };
		int width = computedArray.length;
		int height = computedArray[0].length;
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				assertEquals("Mistake at (" + x + "," + y + "):", correctArray[x][y], computedArray[x][y]);
			}
		}
	}

}