View Javadoc

1   package com.dvp.tutoriel.fibonacci;
2   
3   import static junit.framework.Assert.assertEquals;
4   
5   import org.junit.Test;
6   
7   public abstract class AbstractMaCalculetteTest {
8   
9   	protected static Calculette calculette;
10  	
11  
12  	/**
13  	 * Test du calcul de la Suite de Fibonacci.
14  	 * 
15  	 * REGLE RG024.1 : f(1) = 1
16  	 * 
17  	 * PARAM n = 1 
18  	 * RESULT = 1
19  	 */
20  	@Test
21  	public void testFibonacci_RG024_1() {
22  		// Arrange
23  		final Integer n = 1;
24  		final long resultatAttendu = 1;
25  
26  		// Act and assert
27  		testFibonacci_RG024_x(n, resultatAttendu);
28  	}
29  	
30  	/**
31  	 * Test du calcul de la Suite de Fibonacci.
32  	 * 
33  	 * REGLE RG024.2 : f(2) = 1
34  	 * 
35  	 * PARAM n = 2 
36  	 * RESULT = 1
37  	 */
38  	@Test
39  	public void testFibonacci_RG024_2() {
40  		// Arrange
41  		final Integer n = 2;
42  		final long resultatAttendu = 1;
43  
44  		// Act and assert
45  		testFibonacci_RG024_x(n, resultatAttendu);
46  	}
47  	
48  	/**
49  	 * Test du calcul de la Suite de Fibonacci.
50  	 * 
51  	 * REGLE RG024.3.a : f(3) = 2
52  	 * 
53  	 * PARAM n = 3 
54  	 * RESULT = 2
55  	 */
56  	@Test
57  	public void testFibonacci_RG024_3_a() {
58  		// Arrange
59  		final Integer n = 3;
60  		final long resultatAttendu = 2;
61  
62  		// Act and assert
63  		testFibonacci_RG024_x(n, resultatAttendu);
64  	}
65  	
66  	/**
67  	 * Test du calcul de la Suite de Fibonacci.
68  	 * 
69  	 * REGLE RG024.3.b : f(4) = 3
70  	 * 
71  	 * PARAM n = 4 
72  	 * RESULT = 3
73  	 */
74  	@Test
75  	public void testFibonacci_RG024_3_b() {
76  		// Arrange
77  		final Integer n = 4;
78  		final long resultatAttendu = 3;
79  
80  		// Act and assert
81  		testFibonacci_RG024_x(n, resultatAttendu);
82  	}
83  	
84  	/**
85  	 * Test du calcul de la Suite de Fibonacci.
86  	 * 
87  	 * REGLE RG024.3.c : f(5) = 5
88  	 * 
89  	 * PARAM n = 5 
90  	 * RESULT = 5
91  	 */
92  	@Test
93  	public void testFibonacci_RG024_3_c() {
94  		// Arrange
95  		final Integer n = 5;
96  		final long resultatAttendu = 5;
97  
98  		// Act and assert
99  		testFibonacci_RG024_x(n, resultatAttendu);
100 	}
101 	
102 	/**
103 	 * Test du calcul de la Suite de Fibonacci.
104 	 * 
105 	 * REGLE RG024.3.d : f(6) = 8
106 	 * 
107 	 * PARAM n = 6 
108 	 * RESULT = 8
109 	 */
110 	@Test
111 	public void testFibonacci_RG024_3_d() {
112 		// Arrange
113 		final Integer n = 6;
114 		final long resultatAttendu = 8;
115 
116 		// Act and assert
117 		testFibonacci_RG024_x(n, resultatAttendu);
118 	}
119 	
120 	/**
121 	 * Test du calcul de la Suite de Fibonacci.
122 	 * 
123 	 * REGLE RG024.3.e : f(7) = 13
124 	 * 
125 	 * PARAM n = 7 
126 	 * RESULT = 13
127 	 */
128 	@Test
129 	public void testFibonacci_RG024_3_e() {
130 		// Arrange
131 		final Integer n = 7;
132 		final long resultatAttendu = 13;
133 
134 		// Act and assert
135 		testFibonacci_RG024_x(n, resultatAttendu);
136 	}
137 	
138 	/**
139 	 * Test du calcul de la Suite de Fibonacci.
140 	 * 
141 	 * REGLE RG024.3.f : f(8) = 21
142 	 * 
143 	 * PARAM n = 8 
144 	 * RESULT = 21
145 	 */
146 	@Test
147 	public void testFibonacci_RG024_3_f() {
148 		// Arrange
149 		final Integer n = 8;
150 		final long resultatAttendu = 21;
151 
152 		// Act and assert
153 		testFibonacci_RG024_x(n, resultatAttendu);
154 	}
155 	
156 	/**
157 	 * Test du calcul de la Suite de Fibonacci.
158 	 * 
159 	 * REGLE RG024.4.a : Il n'est pas possible de calculer la valeur de la Suite
160 	 * de Fibonacci pour un rang negatif ou nul. 
161 	 * 
162 	 * PARAM n = 0 
163 	 * RESULT = Exception
164 	 */
165 	@Test(expected = IllegalArgumentException.class)
166 	public void testFibonacci_RG024_4_a() {
167 		// Arrange
168 		final Integer n = 0;
169 
170 		// Act and assert
171 		testFibonacci_RG024_x(n, null);
172 	}
173 	
174 	/**
175 	 * Test du calcul de la Suite de Fibonacci.
176 	 * 
177 	 * REGLE RG024.4.b : Il n'est pas possible de calculer la valeur de la Suite
178 	 * de Fibonacci pour un rang negatif ou nul. 
179 	 * 
180 	 * PARAM n = -1 
181 	 * RESULT = Exception
182 	 */
183 	@Test(expected = IllegalArgumentException.class)
184 	public void testFibonacci_RG024_4_b() {
185 		// Arrange
186 		final Integer n = -1;
187 
188 		// Act and assert
189 		testFibonacci_RG024_x(n, null);
190 	}
191 	
192 	/**
193 	 * Test du calcul de la Suite de Fibonacci.
194 	 * 
195 	 * REGLE RG024.5 : f(55) = 139583862445
196 	 * 
197 	 * PARAM n = 55 
198 	 * RESULT = 225851433717 (en moins de 2 secondes)
199 	 */
200 	@Test(timeout = 2000)
201 	public void testFibonacci_RG024_5() {
202 		// Arrange
203 		final Integer n = 55;
204 		final long resultatAttendu = 139583862445L;
205 
206 		// Act and assert
207 		testFibonacci_RG024_x(n, resultatAttendu);
208 	}
209 	
210 	/**
211 	 * Test du calcul de la Suite de Fibonacci.
212 	 * 
213 	 * REGLE RG024.6 : f(49) = 7778742049
214 	 * 
215 	 * PARAM n = 49 
216 	 * RESULT = 7778742049 (en moins de 1 seconde)
217 	 */
218 	@Test(timeout = 1000)
219 	public void testFibonacci_RG024_6() {
220 		// Arrange
221 		final Integer n = 49;
222 		final long resultatAttendu = 7778742049L;
223 
224 		// Act and assert
225 		testFibonacci_RG024_x(n, resultatAttendu);
226 	}
227 
228 
229 
230 	protected void testFibonacci_RG024_x(Integer n, Long resultatAttendu) {
231 		// Act
232 		final Long resultatCalcule = calculette.fibonacci(n);
233 
234 		// Assert
235 		assertEquals(resultatAttendu, resultatCalcule);
236 	}
237 
238 }