public class PalindromeCheckerTest {
public static void main(String[] args) {
int testsPassed = 0;
int testsAttempted = 0;
PalindromeChecker<Character> pcC1 = new PalindromeChecker<Character>(
toCharArray("abcd"));
if (pcC1.isPalindrome()) {
testsPassed++;
}
testsAttempted++;
PalindromeChecker<Character> pcC2 = new PalindromeChecker<Character>(
toCharArray("stack"));
if (!pcC2.isPalindrome()) {
testsPassed++;
}
testsAttempted++;
String[] arr1 = { "I", "love", "CS", "love", "I" };
PalindromeChecker<String> pcS1 = new PalindromeChecker<String>(arr1);
if (pcS1.isPalindrome()) {
testsPassed++;
}
testsAttempted++;
// Here you will write some more tests
// ....
//
// If you do the extra credit, uncomment these tests, and write
// some of your own.
// PalindromeChecker<Character> pcExtra1 = new
// PalindromeChecker<Character>(
// sentenceToCharArray("A man, a plan, a canal. Panama."));
// if (pcExtra1.isPalindrome()) {
// testsPassed++;
// }
// testsAttempted++;
//
// PalindromeChecker<Character> pcExtra2 = new
// PalindromeChecker<Character>(
// sentenceToCharArray("I Palindrome I"));
// if (!pcExtra2.isPalindrome()) {
// testsPassed++;
// }
// testsAttempted++;
// If you do the extra extra credit, uncomment these tests, and write
// some of your own.
/*PalindromeChecker<Integer> pcExtraExtra1 = new PalindromeChecker<Integer>(
intToIntArray(1331));
if (pcExtraExtra1.isPalindrome()) {
testsPassed++;
}
testsAttempted++;
PalindromeChecker<Integer> pcExtraExtra2 = new PalindromeChecker<Integer>(
intToIntArray(1337));
if (!pcExtraExtra2.isPalindrome()) {
testsPassed++;
}
testsAttempted++;*/
System.out.println("Congratulations. You passed " + testsPassed
+ " of " + testsAttempted + " tests!");
}
/**
* @param s
* a String to be converted to an array of Character objects
* @return the array of Characters created
*/
private static Character[] toCharArray(String s) {
Character[] array = new Character[s.length()];
for (int i = 0; i < s.length(); i++) {
array[i] = new Character(s.charAt(i));
}
return array;
}
// Extra Credit: Write (and document) a utility function that takes in a
// single string that is a sentence, and returns an array of Characters
// (only lowercase,
// no punctuation or whitespace) that a PalindromeChecker<Character> can
// take as input. This is so you can test that something like "A man, a
// plan, a canal. Panama." is a palindrome based on the characters, even
// though it is not if we look at the words.
// private static Character[] sentenceToCharArray(String sentence) {
// return null;
// }
// Extra Extra Credit: Write (and document) a utility function that takes in
// an Integer and converts it to an array of Integers that a
// PalindromeChecker<Integer> can take as input. The array of Integers
// will be the digits in the base-10 representation of the input. So,
// for example, intToIntArray(12345) will return [1,2,3,4,5]
//private static Integer[] intToIntArray(Integer input) {
// return null;
//}
}