Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Test driven development The following directory structure comp |-- lib |__ |-- c

ID: 665011 • Letter: T

Question

Test driven development

The following directory structure

comp

|-- lib

|__ |-- checkstyle-6.5-all.jar

|__ |-- hamcrest-core-1.3.jar

|__ -- junit-4.12.jar

|-- Makefile

|-- src

|__ -- PalindromeChecker.java

-- tests

|-- MyTestRunner.java

-- PalindromeCheckerTest.java

All of your file, class, and method names, if specified in this assignment, must have the exact names specified

The purpose of this assignment is to make you more familiar with recursion and test driven development. In PalindromeChecker.java you will find a method with the header:

public class PalindromeChecker {

public static boolean isPalindrome(String str) {

str = str.toLowerCase();

// your code goes here

This method should return true if str is a palindrome, and false otherwise. A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some examples of palindromes:

• Able was I, ere I saw Elba

• A man, a plan, a canal, Panama

• Desserts, I stressed

• Kayak

Note from the examples above, you should ignore case, spaces, and punctuation. Your implementation of isPalindrome must be recursive. Furthermore, you must write your code using the test driven development methodology. You must write your tests in PalindromeCheckerTest.java

import static org.junit.Assert.assertFalse;

import static org.junit.Assert.assertTrue;

import static org.junit.Assert.fail;

import org.junit.Test;

public class PalindromeCheckerTest {

// your tests go here

You can check that:

1. your code builds with make build

2. your code pases your tests with make test

3. your code adheres to the Google java style with make checkstyle

If you simply run make then the above three things will be checked in order

Hese are good secondary measures of whether you

followed TDD:

•Your code passes the Checkstyle audit.

•Your code has an appropriate amount of commenting.

•You have an appropriate number of tests.

•Your code passes all your tests

•Your code is not overly complex.

•Your impementation of the required method is correct.

Explanation / Answer

PalindromeChecker.java

public class PalindromeChecker {

public static boolean isPalindrome(String str)

{

str = str.toLowerCase();
int low = 0;
int high = str.length() - 1;
while (high > low)
{
    if (str.toLowerCase() != str.toHignCase()))

{
    return false;
    }
    low++;
    high--;
    }
    return true;
}

PalindromeCheckerTest.java

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
public class PalindromeCheckerTest
{


    public void test1()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertFalse(check.isPalindrome(input));
    }
  
    public void test2()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertFalse(check.isPalindrome(input));
    }

    public void test3()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertFalse(check.isPalindrome(input));
    }

  
    public void test4()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertFalse(check.isPalindrome(input));
    }

    public void test5()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertTrue(check.isPalindrome(input));
    }


    public void test6() {
        PalindromeChecker check = new PalindromeChecker();
        assertTrue(check.isPalindrome(input));
    }


    public void test7()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertTrue(check.isPalindrome(input));
    }

  
    public void test8()
    {
        PalindromeChecker check = new PalindromeChecker();
        assertTrue(check.isPalindrome(input));
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote