Sei sulla pagina 1di 13

SOFTWARE TESTING – 3006

Reg.No: 15MIS0087

Name : P.Ragavendhar

Question 1 :

TestScript :-
package javaapplication3;
import java.text.NumberFormat;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class AccountTest {
public AccountTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}

@Test
public void testDeposit() {
System.out.println("deposit");
float amount = 100.0F;
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
boolean expResult = true;
boolean result = instance.deposit(amount);
assertEquals(expResult, result);
}

@Test
public void testWithdraw() {
System.out.println("withdraw");
float amount = 50.0F;
float fee = 10.0F;
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
boolean expResult = false;
boolean result = instance.withdraw(amount, fee);
assertEquals(expResult, result);
}
@Test
public void testAddInterest() {
System.out.println("addInterest");
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
instance.addInterest();
}

@Test
public void testGetBalance() {
System.out.println("getBalance");
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
float expResult = 100.0F;
float result = instance.getBalance();
assertEquals(expResult, result, 0.0);
}

@Test
public void testGetAccountNumber() {
System.out.println("getAccountNumber");
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
long expResult = 1234567890L;
long result = instance.getAccountNumber();
assertEquals(expResult, result);
}

@Test
public void testToString() {
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("toString");
Account instance = new Account("Ragavendhar",1234567890L,100.0F);
String expResult = "1234567890"+"\t" + "ragavendhar" + "\t" + fmt.format(100);
String result = instance.toString();
assertEquals(expResult, result);
}
}

Output :
2)Create a class called 2DMatrix that implements the methods below:

public static void swithRows(int[][] anArray)

pubic static void switchColumns(char [][] anArray)

Follow the steps below to implement them:

I. Write the implementation of the method switchRows

This method receives a 2-dimensional array of integers and switches the values in
opposing rows. For example, given a 2-dimensional array (shown left, below), the method
should swap its row values (shown right, below) where the values on the 1 st row (index 0)
are switched with the values on the 5th row (index 4), and the values on the 2nd row (index
1) are switched with those on the 4th (index 3). Since this example shows an array with
odd-numbered rows, the 3rd row (index 2) did not have an opposing row with which to get
swapped. Nevertheless, the method should work with any 2-dimensional array.

Java Code :
package javaapplication2;

import java.util.Scanner;

public class JavaApplication2 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Enter the row's:");

int row = input.nextInt();


System.out.println("Enter the column's:");

int col = input.nextInt();

int array[][] = new int[row][col];

for(int i = 0 ; i < row ; i++) {

for (int j = 0 ; j < col ; j++) {

System.out.println("[" + i +" " +j + "]");

array[i][j] = input.nextInt();

System.out.println("You have entered : ");

for (int i = 0; i < row; i++) {

for (int j = 0; j < col; j++) {

System.out.print(array[i][j] + " ");

System.out.println();

int[][] revArr = new int[array.length][array[0].length];

for(int i = array.length-1 ; i>=0 ; i--) {

for(int j = 0 ; j<array[i].length ; j++) {

revArr[array.length-1-i][j] = array[i][j];

System.out.println(" ");

System.out.println("After interchanging Array: ");

for (int i = 0; i < row; i++) {


for (int j = 0; j < col; j++) {

System.out.print(revArr[i][j] + " ");

System.out.println();

TestScript :-
package javaapplication2;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class ArrayIntTest {
public JavaApplication2Test() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}

@Test
public void testSwap_row() {
System.out.println("swap_row");
int row = 5;
int col = 3;
int[][] array = {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15}};
JavaApplication2 instance = new JavaApplication2();
int[][] expResult ={{13,14,15},{10,11,12},{7,8,9},{4,5,6},{1,2,3}};
int[][] result = instance.swap_row(row, col, array);
assertArrayEquals(expResult, result);
}
}

Output:
ii). Write the implementation of the method switchColumns. This method receives a 2-
dimensional array of characters and switches the values in opposing columns. For example,
given a 2-dimensional array (shown left, below), the method should swap its column values
(shown right, below). The method should work with any 2-dimensional array.

Create a JUnit test class, TestMatrixTable, and write test cases which exercise the methods
of the 2DMatrix class. Compile your classes and and run the JUnit tests. Correct any
defects in your tests. If your tests reveal any defects in the logic of the 2DMatrix, repair
them.

Java Code:
package javaapplication1;

import java.util.Scanner;

public class javaApplication1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);


System.out.println("Enter the row's:");

int row = input.nextInt();

System.out.println("Enter the column's:");

int col = input.nextInt();

String array[][] = new String[row][col];

input.nextLine();

for(int i = 0 ; i < row ; i++) {

for (int j = 0 ; j < col ; j++) {

System.out.println("[" + i +" " +j + "]");

array[i][j] = input.nextLine();

System.out.println("You have entered : ");

for (int i = 0; i < row; i++) {

for (int j = 0; j < col; j++) {

System.out.print(array[i][j] + " ");

System.out.println();

for (int j = 0; j < array.length; j++) {

for (int i = 0; i < array[j].length / 2; i++) {

String temp = array[j][i];

array[j][i] = array[j][array[j].length - i - 1];

array[j][array[j].length - i - 1] = temp;

}
System.out.println("After interchanging Array");

for (int i = 0; i < row; i++) {

for (int j = 0; j < col; j++) {

System.out.print(array[i][j] + " ");

System.out.println();

Test Script:
package javaapplication1;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class JavaApplication1Test {
public JavaApplication1Test() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}

@Test
public void testSwap_row() {
System.out.println("swap_row");
int row = 4;
int col = 3;
String[][] array = {{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'}};
JavaApplication1 instance = new JavaApplication1();
String[][] expResult = {{'c','b','a'},{'f','e','d'},{'i','h','g'},{'l','k','j'}};
String[][] result = instance.swap_row(row, col, array);
System.out.println(result);
assertEquals(expResult, result);
}
}

Output :-

Potrebbero piacerti anche