Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

software testing without making any changes to the java classes provided below, come up with some junit test cases to test the code. To get

software testing

without making any changes to the java classes provided below, come up with some junit test cases to test the code.

To get you started, here are four test cases you must implement:

Next, test to see if reverseNCharacters() provides the correct output for the same input and grouping when padding is enabled (in this case, etePiP r repkcipa decep fo kcip delkpep srepXXX.).

Use the setString() function in MyCustomStringInterface to set the value to 123456789. Then, use the convertDigitsToNamesInSubstring() function to convert numbers between 4 and 7 (inclusive) to their written form. Test to see if the string is now equal to the correct value (in this case, 123fourfivesixseven89).

MyCustomString

public class MyCustomString implements MyCustomStringInterface { private String string;

@Override public String getString() { return string; }

@Override public void setString(String string) { this.string = string; }

@Override public int countNumbers() { StringBuffer tmpString = new StringBuffer(); int count=0; boolean inNumber=false; //avoid null pointer exception! if(string==null || string.isEmpty()) return 0; for (int i = 0; i < string.length(); i++) { char ch = string.charAt(i); if (Character.isDigit(ch)) { if (!inNumber) { count++; inNumber = true; } } else { if (inNumber) { inNumber = false; } } } return count; }

@Override public String reverseNCharacters(int n, boolean padded) { if (string == null) { throw new NullPointerException(); } if (n <= 0) { throw new IllegalArgumentException(); } StringBuffer tmpString = new StringBuffer(); StringBuffer resultString = new StringBuffer(); StringBuffer currString = new StringBuffer(string);

int i; for (i = 0; i + n < currString.length(); i+=n) { tmpString = tmpString.append(new StringBuffer(currString.substring(i,i+n)).reverse()); } if (padded) { for (int x = n - (currString.length() - i); x > 0; x--) currString.append('X'); } tmpString = tmpString.append(new StringBuffer(currString.substring(i)).reverse());

return tmpString.toString(); }

@Override public void convertDigitsToNamesInSubstring(int startPosition, int endPosition) { if (string == null) { throw new NullPointerException(); } if ((startPosition > endPosition)) { throw new IllegalArgumentException(); }

if (endPosition > string.length() || (startPosition < 1)){ throw new MyIndexOutOfBoundsException(); } StringBuffer tmpString = new StringBuffer(); String tmpDigit = new String(); boolean look_back = false; for (int i = 0; i < string.length(); i++) { char ch = string.charAt(i); if ((i < startPosition - 1) || (i > endPosition - 1)) { if(look_back) { look_back = false; } tmpString.append(ch); continue; } else { if (Character.isDigit(ch)) { switch (ch) { case '0': tmpDigit = "Zero"; break; case '1': tmpDigit = "One"; break; case '2': tmpDigit = "Two"; break; case '3': tmpDigit = "Three"; break; case '4': tmpDigit = "Four"; break; case '5': tmpDigit = "Five"; break; case '6': tmpDigit = "Six"; break; case '7': tmpDigit = "Seven"; break; case '8': tmpDigit = "Eight"; break; case '9': tmpDigit = "Nine"; break; } if(look_back) tmpString.append(tmpDigit.toLowerCase()); else tmpString.append(tmpDigit); look_back = true; } else { if(look_back){ look_back = false;} tmpString.append(ch);

} }

MyCustomStringInterface

} string = tmpString.toString(); } }

public interface MyCustomStringInterface {

String getString();

void setString(String string);

int countNumbers();

String reverseNCharacters(int n, boolean padded);

void convertDigitsToNamesInSubstring(int startPosition, int endPosition); } MyIndexOutOfBoundsException

public class MyIndexOutOfBoundsException extends RuntimeException { private static final long serialVersionUID = 8226094121089030034L;

public MyIndexOutOfBoundsException(String message) { super(message); }

public MyIndexOutOfBoundsException() { super(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago

Question

What qualities do you see as necessary for your line of work?

Answered: 1 week ago