I am trying to use junit to test my code. The code is for rot13. Here is my actu
ID: 3621892 • Letter: I
Question
I am trying to use junit to test my code. The code is for rot13. Here is my actual code:
public static char[] rot13 (char x[], int n)
{
if (n==0){
if (x[n] >= 'a' && x[n] <= 'm') x[n] += 13;
else if (x[n] >= 'n' && x[n] <= 'z') x[n] -= 13;
else if (x[n] >= 'A' && x[n] <= 'M') x[n] += 13;
else if (x[n] >= 'N' && x[n] <= 'Z') x[n] -= 13;
}
return x;
}
And here is my junit code:
import junit.framework.TestCase;
import junit.framework.Assert;
/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class mymathTest extends TestCase {
public void testrot13b(String args[]) {
String testString;
char [] CharArray;
char [] a= new char[0];
char expected; // Value we expect to see as result
char actual; // Actual value that method returns
int testValueY= 0;
a[0]='a';
testString="a";
CharArray=testString.toCharArray();
expected = 'n';
a = rot13b.rot13(CharArray, testValueY);
actual = a[0];
Assert.assertEquals( expected, actual );
}
}
I am keep on getting this error: Static Error: This class does not have a static void main method accepting String[].
My second test is for this code here:
if (n==0){
if (x[n] >= 'a' && x[n] <= 'm') x[n] += 13;
else if (x[n] >= 'n' && x[n] <= 'z') x[n] -= 13;
else if (x[n] >= 'A' && x[n] <= 'M') x[n] += 13;
else if (x[n] >= 'N' && x[n] <= 'Z') x[n] -= 13;
return x;
}
else{
if (x[n] >= 'a' && x[n] <= 'm') x[n] += 13;
else if (x[n] >= 'n' && x[n] <= 'z') x[n] -= 13;
else if (x[n] >= 'A' && x[n] <= 'M') x[n] += 13;
else if (x[n] >= 'N' && x[n] <= 'Z') x[n] -= 13;
return cipher(x,n-1);
}
Where I have to give "Hello" and my result should be "Uryyb". Any ideas?
Explanation / Answer
Hey guys this is really urgent, just help me do the first part.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.