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