package RegularExpression;

public class UnitTest
{
	public static void main (String [] args) throws Exception
	{
		//URL Tests
		RE testRE1 = new RE ("[^://]+:////[a-zA-Z/.]+//?/s*", true);

		if (testRE1.matches ("http://www.Fokno.org/"))
		{
			System.out.println ("URL Test 1 - Passed");
		}
		else
		{
			System.out.println ("URL Test 1 - Failed");
		}

		if (testRE1.matches ("http://www.cs.unr.edu"))
		{
			System.out.println ("URL Test 2 - Passed");
		}
		else
		{
			System.out.println ("URL Test 2 - Failed");
		}

		if (testRE1.matches ("http:/www.fokno.org/"))
		{
			System.out.println ("URL Test 3 - Failed");
		}
		else
		{
			System.out.println ("URL Test 3 - Passed");
		}

		//Inner Alpha Tests
		RE testRE2 = new RE (".*[A-Z]+.*", false);

		if (testRE2.matches ("ABCDEFG"))
		{
			System.out.println ("Inner Alpha 1 - Passed");
		}
		else
		{
			System.out.println ("Inner Alpha 1 - Failed");
		}

		if (testRE2.matches ("abcdefg"))
		{
			System.out.println ("Inner Alpha 2 - Passed");
		}
		else
		{
			System.out.println ("Inner Alpha 2 - Failed");
		}

		if (testRE2.matches ("--!!@@##lettersGoHere$$%%^^&&**"))
		{
			System.out.println ("Inner Alpha 3 - Passed");
		}
		else
		{
			System.out.println ("Inner Alpha 3 - Failed");
		}

		if (testRE2.matches ("--!!@@##$$%%^^&&**"))
		{
			System.out.println ("Inner Alpha 4 - Failed");
		}
		else
		{
			System.out.println ("Inner Alpha 4 - Passed");
		}

		//Parentheses Tests
		RE testRE3 = new RE ("(ab){0,10}((cd)*e(f(g)+h)*i)?j", true);

		if (testRE3.matches ("abcdefghij"))
		{
			System.out.println ("Parentheses 1 - Passed");
		}
		else
		{
			System.out.println ("Parentheses 1 - Failed");
		}

		if (testRE3.matches ("j"))
		{
			System.out.println ("Parentheses 2 - Passed");
		}
		else
		{
			System.out.println ("Parentheses 2 - Failed");
		}

		if (testRE3.matches ("abababababcdcdcdcdcdefggggggggghij"))
		{
			System.out.println ("Parentheses 3 - Passed");
		}
		else
		{
			System.out.println ("Parentheses 3 - Failed");
		}

		if (testRE3.matches ("abababababcdcdcdcdcdefhifghij"))
		{
			System.out.println ("Parentheses 4 - Failed");
		}
		else
		{
			System.out.println ("Parentheses 4 - Passed");
		}

		//Other tests
		RE testRE4 = new RE ("<,>|<;>\n", true);
		String [] parts = testRE4.split ("these are words<,>separated by comma<,>tags<,>isn't it fun?<;>\nyes it is<,>I like it a lot.<;>\n");
		if (parts[0].equals ("these are words") && parts[1].equals ("separated by comma") && parts[2].equals ("tags") && parts[3].equals ("isn't it fun?") && parts[4].equals ("yes it is") && parts[5].equals ("I like it a lot."))
		{
			System.out.println ("Split 1 - Passed");
		}
		else
		{
			System.out.println ("Split 1 - Failed");
		}

		int index1 = testRE4.indexOf ("these are words<,>separated by comma<,>tags<,>isn't it fun?<;>\nyes it is<,>I like it a lot.<;>\n", 0);
		if (index1 == 15)
		{
			System.out.println ("Index 1 - Passed");
		}
		else
		{
			System.out.println ("Index 1 - Failed");
		}

		int index2 = testRE4.indexOf ("these are words", 0);
		if (index2 == -1)
		{
			System.out.println ("Index 2 - Passed");
		}
		else
		{
			System.out.println ("Index 2 - Failed");
		}

		int index3 = testRE4.indexOf ("Hello<,>there", 13);
		if (index2 == -1)
		{
			System.out.println ("Index 3 - Passed");
		}
		else
		{
			System.out.println ("Index 3 - Failed");
		}

		//Speed Tests
		long startTime1 = System.currentTimeMillis ();

		for (int index = 0; index < 1000; index++)
		{
			RE speedTestRE = new RE (index + "(a){1,4}((cd)+(ef)?g)*h-[^://]+:////[a-zA-Z/.]+//?", true);
		}

		long stopTime1 = System.currentTimeMillis ();

		RE speedTestRE = new RE ("(a){1,4}((cd)+(ef)?g)*h-[^://]+:////[a-zA-Z/.]+//?", true);

		long startTime2 = System.currentTimeMillis ();

		for (int index = 0; index < 1000; index++)
		{
			speedTestRE.matches ("aaacdcdcdefgcdgh-http://www.somewherenice.com/");
		}

		long stopTime2 = System.currentTimeMillis ();

		System.out.println ("RE Build Time:    " + ((double) (stopTime1 - startTime1) / 1000.0) + "s");
		System.out.println ("     Avg:         " + (((double) (stopTime1 - startTime1) / 1000.0) / 1000.0) + "s");
		System.out.println ("RE Matching Time: " + ((double) (stopTime2 - startTime2) / 1000.0) + "s");
		System.out.println ("     Avg:         " + (((double) (stopTime2 - startTime2) / 1000.0) / 1000.0) + "s");
	}
}
