Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import search.Cauta;
- import junit.framework.Assert;
- import junit.framework.TestCase;
- public class CautaTest extends TestCase {
- public CautaTest(String x)
- {
- super(x);
- }
- private ArrayList<String> in = new ArrayList<String>();
- @Override
- protected void setUp() throws Exception {
- in = new ArrayList<String>();
- in.add("first");
- in.add("second");
- in.add("...");
- in.add("last");
- }
- @Override
- protected void tearDown()
- {
- in = null;
- }
- public void testFirst()
- {
- Integer r = Cauta.cauta( in, "first");//cauta un elem intr-o lista de strings
- Assert.assertEquals(new Integer(0), r);
- }
- public void testMIddle()
- {
- Integer r = Cauta.cauta( in, "...");
- Assert.assertEquals(new Integer(2), r);
- }
- public void testNullList()
- {
- Integer r = Cauta.cauta( null, "...");
- Assert.assertEquals(new Integer(-1), r);//-1 caz exceptie, nu se gaseste
- }
- public void testNullString()
- {
- Integer r = Cauta.cauta( in, null);
- Assert.assertEquals(new Integer(-1), r);
- }
- public void testNullStringInList()
- {
- in.add(null);
- Integer r = Cauta.cauta( in, null); //ar trebui sa-l gaseasca, dar nu->bug
- Assert.assertEquals(new Integer(4), r);
- }
- public void testEmpty()
- {
- Integer r = Cauta.cauta( new ArrayList<String>(), "...");
- Assert.assertEquals(new Integer(-1), r);
- }
- public void testOne()
- {
- ArrayList<String> data=new ArrayList<String>();
- data.add("...");
- Integer r = Cauta.cauta( data, "..."); //testam pentru un element
- Assert.assertEquals(new Integer(0), r);
- }
- public void testEnd()
- {
- Integer r = Cauta.cauta( in, "last");
- Integer length = in.toArray().length;
- Assert.assertEquals(new Integer(length - 1), r);
- }
- public void testNotExists()
- {
- System.out.println(in);
- Integer r = Cauta.cauta( in, "notin");
- Assert.assertEquals(new Integer(-1), r);
- }
- public void testPe() {
- Integer r = Cauta.cauta(in, "second");
- Assert.assertEquals(new Integer(1), r);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement