package org.gcube.portlets.user.accountingdashboard;

import org.gcube.portlets.user.accountingdashboard.shared.Constants;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cern.colt.Arrays;
import junit.framework.TestCase;

/**
 * 
 * @author Giancarlo Panichi
 *
 *
 */
public class ColorTest extends TestCase {
	private static Logger logger = LoggerFactory.getLogger(ColorTest.class);

	@Test
	public void testService() {
		if (Constants.TEST_ENABLE) {

			try {
				String[] red = new String[] { "#FF0000", "#FF6347", "#FF7F50", "#FF8C00", "#FFA500", "#8B0000",
						"#B22222", "#800000", "#FFD700", "#FF4500", "#DC143C", "#CD5C5C", "#F08080", "#E9967A",
						"#FA8072", "#FFA07A" };

				String[] cyan = new String[] { "#00FFFF", "#E0FFFF", "#AFEEEE", "#7FFFD4", "#40E0D0", "#48D1CC",
						"#00CED1", "#556B2F", "#66CDAA", "#8FBC8F", "#20B2AA", "#008B8B", "#008080", "#F0FFF0",
						"#F5FFFA", "#778899" };

				String[] purple = new String[] { "#483D8B", "#6A5ACD", "#7B68EE", "#9370DB", "#800080", "#8A2BE2",
						"#9400D3", "#9932CC", "#BA55D3", "#FF00FF", "#FF00FF", "#EE82EE", "#DA70D6", "#DDA0DD",
						"#D8BFD8", "#E6E6FA" };

				String[] yellow = new String[] { "#FFFF00", "#FFFFE0", "#FFFACD", "#FAFAD2", "#FFEFD5", "#FFE4B5",
						"#FFDAB9", "#EEE8AA", "#F0E68C", "#BDB76B", "#FFC0CB", "#FFB6C1", "#FF69B4", "#FF1493",
						"#DB7093", "#C71585" };

				String[] blue = new String[] { "#4B0082", "#663399", "#00008B", "#0000CD", "#0000FF", "#4169E1",
						"#1E90FF", "#00BFFF", "#6495ED", "#87CEEB", "#87CEFA", "#B0E0E6", "#ADD8E6", "#B0C4DE",
						"#4682B4", "#5F9EA0" };

				String[] brown = new String[] { "#FFF8DC", "#FFEBCD", "#FFE4C4", "#FFDEAD", "#F5DEB3", "#DEB887",
						"#D2B48C", "#BC8F8F", "#F4A460", "#DAA520", "#B8860B", "#CD853F", "#D2691E", "#808000",
						"#8B4513", "#A0522D" };

				String[] green = new String[] { "#ADFF2F", "#7FFF00", "#7CFC00", "#00FF00", "#32CD32", "#98FB98",
						"#90EE90", "#00FA9A", "#00FF7F", "#3CB371", "#2E8B57", "#228B22", "#008000", "#006400",
						"#9ACD32", "#6B8E23" };

				logger.debug("Dimension: red=" + red.length + ", cyan=" + cyan.length + ", purple=" + purple.length
						+ ", yellow=" + yellow.length + ", blue=" + blue.length + ", brown=" + brown.length + ", green="
						+ green.length);
				int average = (red.length + cyan.length + purple.length + yellow.length + blue.length + brown.length
						+ green.length) / 7;
				logger.debug("Average: " + average);

				/*
				 * System.out.print("purple=["); for (int i = purple.length - 1;
				 * i > -1; i--) { if (i == purple.length - 1) {
				 * System.out.print("\"" + purple[i] + "\""); } else {
				 * System.out.print(",\"" + purple[i] + "\""); } }
				 * System.out.print("]"); System.out.println("");
				 */

				String[] palette = new String[112];
				int j = 0;
				for (int i = 0; i < 16; i++) {
					j = i * 7;
					palette[j] = red[i];
					palette[j + 1] = cyan[i];
					palette[j + 2] = purple[i];
					palette[j + 3] = yellow[i];
					palette[j + 4] = blue[i];
					palette[j + 5] = brown[i];
					palette[j + 6] = green[i];
				}

				logger.debug("Palette: " + Arrays.toString(palette));
				StringBuilder paletteBuilder = new StringBuilder();
				paletteBuilder.append("[");
				for (int i = 0; i < palette.length; i++) {
					if (i == 0) {
						paletteBuilder.append("'" + palette[i] + "'");

					} else {
						paletteBuilder.append(",'" + palette[i] + "'");
					}
				}
				paletteBuilder.append("]");

				logger.debug("Palette array: " + paletteBuilder.toString());

				assertTrue("Success", true);
			} catch (Throwable e) {
				logger.error(e.getLocalizedMessage(), e);
				fail("Error:" + e.getLocalizedMessage());

			}

		} else {
			assertTrue("Success", true);
		}
	}

}