Skip to content

Sample Code

mharisce edited this page Dec 23, 2013 · 1 revision

Sample Code 1:

    public static void main(String[] args) {
	long[] arr = new long[] { 0, 11, 22, 23, 42, 69, 249, 280, 288, 333,
			370, 436, 439, 466, 487, 510, 512, 555, 584, 591, 611, 613,
			685, 688, 738, 795, 857, 864, 895, 907, 915, 970, 983, 995,
			32856, 70783, 70983, 79999, 799999, 783992, 106184, 153365,
			176691, 247834, 260276, 285221, 358227, 431487, 453806, 456545,
			481327, 543311, 545691, 566842, 677699, 732797, 789326, 879425,
			555274404, 1380680625, 2108690443, 2122621091, 4690422909l,
			5049704579l, 5973477085l, 6652688238l, 8581289084l,
			8670241955l, 2466011839614l, 2795315633506l, 8521420071144l,
			12369239671123l, 20545655499581l, 31703374999539l,
			34827852528021l };
	
	//long[] arr = new long[] { 106184 };

	for (long l : arr) {

		String lStr = String.valueOf(l);
		Palindrome palin = new Palindrome(new char[] { '0', '1', '2', '3',
				'4', '5', '6', '7', '8', '9' }, lStr.toCharArray());

		String nextPalin = palin.nextPalindrome();
		System.out.println(lStr + "\t" + nextPalin);

	}

}

Sample Code 2 (JUnit Testcase):

    @Test
public void testPalindrome6() {
	executeTest(99999999999l, 100000000001l);
}

private void executeTest(long startNumber, long endNumber) {
	String endNumStr = String.valueOf(endNumber);

	// start
	{
		String startNumStr = String.valueOf(startNumber);
		char[] startingValue = startNumStr.toCharArray();
		Palindrome p = new Palindrome(orderdCharArray, startingValue);
		String nextPalindrome = p.nextPalindrome();
		assertEquals("Start", startNumStr, nextPalindrome);
		startNumber++;
	}

	// inbetween
	{
		for (; startNumber < endNumber; startNumber++) {
			String startNumStr = String.valueOf(startNumber);
			Palindrome p = new Palindrome(orderdCharStr, startNumStr);
			String nextPalindrome = p.nextPalindrome();
			assertEquals("In-b/w", endNumStr, nextPalindrome);
		}
	}

	// end
	{
		String startNumStr = String.valueOf(startNumber);
		char[] startingValue = startNumStr.toCharArray();
		Palindrome p = new Palindrome(orderdCharArray, startingValue);
		String nextPalindrome = p.nextPalindrome();
		assertEquals("End", endNumStr, nextPalindrome);
	}
}
Clone this wiki locally
You can’t perform that action at this time.