Professional Documents
Culture Documents
Lab 2.2 Final Record
Lab 2.2 Final Record
2(1)
JUNIT
DATE :
AIM :
To write a java program to perform unit testing on the given program.
ALGORITHM:
BEGIN
STEP 1: Add the Junit and hamcrest-core JAR files to the project
STEP 2: Perform the unit testing using the assert methods available in the Junit package.
END
SOURCE CODE :
RESULT :
EX NO : 2.2(2)
JUNIT
DATE :
AIM :
To write a java program to perform unit testing on the given program.
ALGORITHM:
BEGIN
STEP 1: Add the Junit and hamcrest-core JAR files to the project
STEP 2: Perform the unit testing using the assert methods available in the Junit package.
STEP 3: Obtain the Test results.
END
SOURCE CODE :
public class Palin {
public String Palindrome(String s){
String rev = "";
for(int i=s.length()-1;i>=0;i--){
rev+=Character.toString(s.charAt(i));
}
return rev;
}
}
Test File :
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class PaliTest {
Palin obj = new Palin();
@Test
public void test(){
RESULT :
EX NO : 2.2(3)
JUNIT
DATE :
AIM :
To write a java program to perform unit testing on the given program.
ALGORITHM:
BEGIN
STEP 1: Add the Junit and hamcrest-core JAR files to the project
STEP 2: Perform the unit testing using the assert methods available in the Junit package.
STEP 3: Obtain the Test results.
END
SOURCE CODE :
import java.util.Arrays;
public class removeDuplicate {
public String[] removeDuplicates(String[] input){
input = Arrays.stream(input).distinct().toArray(String[]::new);
return input;
}
}
Test File :
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
public class RemoveTest {
removeDuplicate obj = new removeDuplicate();
@Test
public void test(){
String[] input = {"Hi","Hello","Hey","Hi","Yayy"};
OUTPUT :
EX NO : 2.2(4)
JUNIT
DATE :
AIM :
To write a java program to perform unit testing on the given program.
ALGORITHM:
BEGIN
STEP 1: Add the Junit and hamcrest-core JAR files to the project
STEP 2: Perform the unit testing using the assert methods available in the Junit package.
STEP 3: Obtain the Test results.
END
SOURCE CODE :
public class Binary {
public byte add(byte b1, byte b2) {
return (byte) (b1 + b2);
}
public short add(short b1, short b2) {
return (short) (b1 + b2);
}
public int[] printBinary(int decimal) {
int binary[] = new int[4];
int index = 0;
while(decimal > 0){
binary[index++] = decimal%2;
decimal = decimal/2;
OUTPUT :