/**
 * Basic unit test for SphericalCone class
 * @author Mark Menor
 */

public class SphericalConeTester
{
	public static void main(String[] args)
	{
		// Maximum difference from expected value
		// Set how strict you want equality to be
		final double EPS = 0.00001;
		
		// Case 1: Creating new SphericalCone instance
		SphericalCone sc = new SphericalCone();
		test("Constructor", sc != null);
		
		// Case 2: Slant height
		double sh = sc.getSlantHeight(3.0, 4.0);
		double expSh = 5.0;
		test("Slant height", equals(sh, expSh, EPS));
		
		// Case 3: Volume
		double vol = sc.getVolume(3.0, 4.0);
		double expVol = 52.35987755982988;
		test("Volume", equals(vol, expVol, EPS));
		
		// Case 4: Surface Area
		double sa = sc.getSurfaceArea(3.0, 4.0);
		double expSa = 78.53981633974483;
		test("Surface Area", equals(sa, expSa, EPS));
	}
	
	
	/*
	 * Prints the name of the test case and [PASS] or [FAIL] based on
	 * test condition is true or false, respectively.
	 * @param testCaseName ame of test case to print
	 * @param condition if true print [PASS], [FAIL] otherwise
	 */
	public static void test(String testCaseName, boolean condition)
	{
		System.out.print("Case [" + testCaseName + "]: ");
		
		if (condition)
		{
			System.out.println("[PASS]");
		}
		else 
		{
			System.out.println("[FAIL]");
		}
	}
	
	/*
	 * Checks if the computed number and the expected number are close enough
	 * to be considered equal
	 * @param c computed number
	 * @param e expected number
	 * @param epsilon the maximum distance between c and e to be considered 
	 *                equal
	 * @return true if distance between c and e is less than epsilon, 
	 *         false otherwise
	 */
	public static boolean equals(double c, double e, double epsilon)
	{
		if (Math.abs(c - e) <= epsilon)
		{
			return true;
		}
		else 
		{
			System.out.println("Computed " + c + "but expected " + e);
			return false;
		}
	}
}