IterateurListeChaineeTest.java
01 package fr.isae.lists;
02 
03 import org.junit.*;
04 import static org.junit.Assert.*;
05 
06 /**
07  *  Unit Test for class IterateurListeChainee. Use the following lists
08  *  for tests: <code>[]</code><code>[1]</code> and
09  *  <code>[1, 2, 3, 4, 5, 6, 7]</code>
10  *
11  *
12  * Created: Wed Nov  2 16:37:09 2011
13  *
14  @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
15  @version 1.0
16  */
17 public class IterateurListeChaineeTest {
18 
19     private ListeChainee el;
20     private ListeChainee ol;
21     private ListeChainee l;
22     private IterateurListeChainee ei;
23     private IterateurListeChainee oi;
24     private IterateurListeChainee li;
25 
26     /**
27      * Setup for the tests.
28      */
29     @Before public void setUp() {
30         this.el = new ListeChainee();
31 
32         this.ol = new ListeChainee();
33         this.ol.ajouter(01);
34 
35         this.l = new ListeChainee();
36         for (int i = 0;  i < 7; i++) {
37             this.l.ajouter(i, i + 1);
38         }
39 
40         this.ei = new IterateurListeChainee(this.el);
41         this.oi = new IterateurListeChainee(this.ol);
42         this.li = new IterateurListeChainee(this.l);
43     }
44 
45     /**
46      * Test method for constructor.
47      */
48     @Test public void testConstructor() {
49         assertEquals(1.0this.oi.elementCourant()0.0);
50         assertEquals(1.0this.li.elementCourant()0.0);
51     }
52 
53     /**
54      * Test method for estTermine with empty list.
55      */
56     @Test public void testTermineEmpty() {
57         assertTrue(this.ei.estTermine());
58     }
59 
60     /**
61      * Test method for estTermine with non-empty list.
62      */
63     @Test public void testTermineNonEmpty() {
64         assertFalse(this.oi.estTermine());
65         assertFalse(this.li.estTermine());
66     }
67 
68     /**
69      * Test method for avancer with one element list.
70      */
71     @Test public void testAvancerOne() {
72         this.oi.avancer();
73         assertTrue(this.oi.estTermine());
74     }
75 
76     /**
77      * Test method for avancer with list.
78      */
79     @Test public void testAvancer() {
80         for (int i = 0; i < 7; i++) {
81             assertFalse(this.li.estTermine());
82             this.li.avancer();
83         }
84         assertTrue(this.li.estTermine());
85     }
86 
87     /**
88      * Test method for elementCourant with list.
89      */
90     @Test public void testElementCourant() {
91         for (int i = 0; i < 7; i++) {
92             assertEquals(i + 1this.li.elementCourant()0.0);
93             this.li.avancer();
94         }
95     }
96 }