package com.approximatrix.draco.utility;

import static org.junit.Assert.*;

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

public class ResultsUtilitiesTest {

	@Test
	public void testOutNumberNumber() {
		Integer one = new Integer(1);
		String strone = ResultsUtilities.OutNumber(one);
		strone = strone.replace(ResultsUtilities.NUMERIC_FLAG, "");
		try {
			assertEquals(1,new Integer(strone).intValue());
		} catch(NumberFormatException nfe) {
			fail("Resulting number was not recognizable");
		}
		
		one = new Integer(-1);
		strone = ResultsUtilities.OutNumber(one);
		strone = strone.replace(ResultsUtilities.NUMERIC_FLAG, "");
		try {
			assertEquals(-1,new Integer(strone).intValue());
		} catch(NumberFormatException nfe) {
			fail("Resulting number was not recognizable");
		}
		
		one = new Integer(-1097000);
		strone = ResultsUtilities.OutNumber(one);
		strone = strone.replace(ResultsUtilities.NUMERIC_FLAG, "");
		assertTrue("Number should be less than zero",new Integer(strone).intValue() < 0);
		
		Double two = new Double(2.0);
		String strtwo = ResultsUtilities.OutNumber(two);
		strtwo = strtwo.replace(ResultsUtilities.NUMERIC_FLAG, "");
		try {
			assertEquals(2.0,new Double(strtwo).doubleValue());
		} catch(NumberFormatException nfe) {
			fail("Resulting number was not recognizable");
		}
		
		two = new Double(-2.0);
		strtwo = ResultsUtilities.OutNumber(two);
		strtwo = strtwo.replace(ResultsUtilities.NUMERIC_FLAG, "");
		try {
			assertEquals(-2.0,new Double(strtwo).doubleValue());
		} catch(NumberFormatException nfe) {
			fail("Resulting number was not recognizable");
		}
		
		two = new Double(-1097000);
		strtwo = ResultsUtilities.OutNumber(two);
		strtwo = strtwo.replace(ResultsUtilities.NUMERIC_FLAG, "");
		assertTrue("Number should be less than zero",new Double(strtwo).doubleValue() < 0);
	}

	@Test
	public void testOutNumberDouble() {
		String strtwo = ResultsUtilities.OutNumber(1.0E-10);
		strtwo = strtwo.replace(ResultsUtilities.NUMERIC_FLAG, "");
		assertEquals(1.0E-10,new Double(strtwo).doubleValue());
		
		strtwo = ResultsUtilities.OutNumber(-1.0E10);
		strtwo = strtwo.replace(ResultsUtilities.NUMERIC_FLAG, "");
		assertEquals(-1.0E10,new Double(strtwo).doubleValue());
	}

}
