QrDroid


Monday, 30 April 2018

CSE534 : Program in eclipse to create test cases for Linear Search using java - Software Testing and Quality Assurance laboratory - CSE 534 by Aniket Pramanik

Information about the quality of the software product or service under test.

Program in eclipse to create test cases for Linear Search

LinearSearch.java
package programs;
import java.util.*;

public class LinearSearch {
 Scanner sc=new Scanner(System.in);
 public int[] input() {
 int a[]=new int[5];
 
 System.out.println("Enter 5 numbers:");
 for(int i=0;i<5;i++) {
  a[i]=sc.nextInt();
 }
 return a;
}
 public boolean search(int a[]) {
  boolean flag=false;
  System.out.println("Enter number to be searched:");
  int num=sc.nextInt();
  for(int i=0;i<a.length;i++) {
   if(num==a[i]) {
    flag=true;
    break;
   }
  }
  return flag;
 }

}

LinearSearchtest.java
package programs;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LinearSearchTest {
LinearSearch l;
 @Before
 public void setUp() throws Exception {
 l=new LinearSearch();}

 @After
 public void tearDown() throws Exception {
 l=null;}

 @Test
 public void test() {
  //assertTrue("Result",l.search(l.input()));//if it is used so both the statemnt below should be comment
  assertEquals(true,l.search(l.input()));
  assertEquals(false,l.search(l.input()));
 }

}
About Developer
Aniket Pramanik
I love to make things simple :)

0 comments:

Post a Comment

 

Version 20.2.1 - 2016 - 2018 - © SSL Technologies And Services Private Limited | Made in India. | Copyright Content