Demo entry 2761988

tests

   

Submitted by red on Sep 27, 2015 at 22:34
Language: Java. Code size: 2.4 kB.

/*@
 * Package : test
 * Date : 24/09/2015
 * Version 1.3
 */


package test;

import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import item.Item;
import item.ItemsSortedList;
import item.ItemsSortedList2;

public class IsSortListTest {
	/** 
	 * Instantiate the objects of class ItemsSortedList +
	 * Definition of list of items.
	 */
	 private  ItemsSortedList list;
	 private ItemsSortedList2 list2;
	 private  ArrayList<Item> items;
	
	 /**
	  * @return : void 
	  * @param : none
	  * Initialization of items List
	  */
    @Before
	public void tinitialisation(){
		items = new ArrayList<Item>();
	}
    
        /**
         * test case of ordered list
         */
    @Test
	public void testOrdredList() {
        list = new ItemsSortedList(new ArrayList<Item>());
        items.add(new Item("Article 1",20));
        items.add(new Item("Article 2",100));
        items.add(new Item("Article 3",254));
        assertEquals(true,list.isSortedList(items));
	}
    
        /**
         * test case of no ordered list
         */
    @Test
	public void testNoOrdredList() {
        list = new ItemsSortedList(new ArrayList<Item>());
        items.add(new Item("Article 1",0));
        items.add(new Item("Article 2",100));
        items.add(new Item("Article 3",254));
        items.add(new Item("Article 4",50));
        assertEquals(false,list.isSortedList(items));
	}
    
	    /**
         * test case of empty list
         */
    @Test
	public void testEmptyList(){
		list = new ItemsSortedList(new ArrayList<Item>());
		items = new ArrayList<Item>();
		assertEquals(true,list.isSortedList(items));
	}
    
	    /**
         * test case of list with one element
         */
    @Test
	public void testOneElement(){
		list = new ItemsSortedList(new ArrayList<Item>());
		items = new ArrayList<Item>();
		items.add(new Item("Article 2",100));
		assertEquals(true,list.isSortedList(items));
	}
    
	    /**
         * test case : list of elements with the same prices
         */
    @Test
	public void testEqualPrice(){
		list2 = new ItemsSortedList2(new ArrayList<Item>());
		items = new ArrayList<Item>();
		items.add(new Item("Article 2",100));
		items.add(new Item("Article 32",100));
		items.add(new Item("Article 42",100));
		assertEquals(true,list2.isSortedList(items));
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).