Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Software Testing: PLEASE ANSWER WILL UPVOTE Without making any changes to the java classes provided below, come up with some junit test cases to test

Software Testing: PLEASE ANSWER WILL UPVOTE

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:

  • Use the setString() function in MyCustomStringInterface to set the value to H3y, l3t'5 put s0me d161ts in this 5tr1n6!11!!. Then test to see if the CountNumbers() function is equal to the number of sequential digits in the original string (in this case, 9).

  • Use the setString() function in MyCustomStringInterface to set the value to Peter Piper picked a peck of pickled peppers.. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, etePiP r repkcipa decep fo kcip delkpep srep.).

  • 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).

    For each of the new test cases, include a comment above the method signature that explains what youre testing for.

    Finally, compile and run your test cases to evaluate whether they pass or fail appropriately, based on the supplied .java files.

-----------------------------------------------------------------------------------------------------------------

MyCustomString.java

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);

} } } string = tmpString.toString(); } }

MyCustomStringInterface.java public interface MyCustomStringInterface { String getString() void setString(String string); int countNumbers(); String reverseNCharacters(int n, boolean padded);

void convertDigitsToNamesInSubstring(int startPosition, int endPosition); }

MyIndexOutOfBoundsException.java

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_2

Step: 3

blur-text-image_3

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago