You are on page 1of 5

package junitf;

import static org.junit.Assert.*;

import org.junit.Test;

public class BinarySearch {

@Test
public void test() {
JunitTesting test=new JunitTesting();
int output =test.Binarysearch(1);
assertEquals(1,output);

}
}

***********************************

package junitf;

import static org.junit.Assert.*;

import org.junit.Test;

public class countA {

@Test
public void test() {
JunitTesting test=new JunitTesting();
int output =test.countA("alphabet");
assertEquals(3,output);
}

******************************************

package junitf;

import static org.junit.Assert.*;


import org.junit.Test;

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

/**
* Test class for Fibonacci class.
*/
public class Fibtest
{
/** Initialise test suite - no-op. */
@Before
public void setUp()
{
}

//** Clean up test suite - no-op. *//*


@After
public void tearDown()
{
}

/** Test fib(1). */


@Test
public void testFib1()
{
assertEquals(1, JunitTesting.fib(1));
}

@Test
public void testFib2()
{
assertEquals(1, JunitTesting.fib(2));
}

************************************************************

package junitf;

import static org.junit.Assert.*;

import org.junit.Test;

public class fibtest2 {

@Test
public void test() {
fail("Not yet implemented");
}

/** Test fib(30). */


@Test
public void testFib30()
{
assertEquals(832040, JunitTesting.fib(30));
}

@Test
public void testFibMinusOne()
{
boolean caught = false;
try
{
JunitTesting.fib(-1);
}
catch (IllegalArgumentException e)
{
caught = true;
}
assertTrue(caught);
}
}

************************************************************************

package junitf;

public class JunitTesting {


int arr[]= {1,2,3,4};
public int square(int x)
{
return x*x;
}
public int countA(String word)
{
int count=0;
for(int i=0;i<word.length();i++)
{
if(word.charAt(i)=='a'||word.charAt(i)=='A') {
count++;}
}
return count;
}

public int Linearsearch(int x)


{
for(int i=0;i<4;i++)
{
if(arr[i]==x)
{
return x;
}
}
return -1;
}
****************************************************************
public int Binarysearch(int x)
{
int low=0;
int high=arr.length-1;
while(low<=high)
{
int midpoint=(low+high)/2;
if(x==arr[midpoint])
return x;
if(x>arr[midpoint])
low=midpoint+1;
if(x<arr[midpoint])
high=midpoint-1;
}
return -1;

public static int fib(int i) {


// TODO Auto-generated method stub

int maxNumber = 10;


int previousNumber = 1;
int nextNumber = 1;

System.out.print("Fibonacci Series of "+maxNumber+"


numbers:");

for (int j = 1; j <= maxNumber; ++j)


{
System.out.print(previousNumber+" ");

int sum = previousNumber + nextNumber;


previousNumber = nextNumber;
nextNumber = sum;
}
return 1;
}

package junitf;

import static org.junit.Assert.*;

import org.junit.Test;

public class Linearsearch {

@Test
public void test() {
JunitTesting test=new JunitTesting();
int output =test.Linearsearch(1);
assertEquals(1,output);
}

package junitf;

import static org.junit.Assert.*;

import org.junit.Test;

public class SquareTesting {

@Test
public void test() {
JunitTesting test=new JunitTesting();
int output =test.square(5);
assertEquals(25,output);
}

You might also like