ajout type entier naturel
Clement COLMERAUER

Clement COLMERAUER commited on 2024-10-07 11:18:01
Showing 25 changed files, with 76 additions and 28 deletions.

... ...
@@ -41,7 +41,7 @@
41 41
 </td>
42 42
 <td>
43 43
 <div class="infoBox" id="duration">
44
-<div class="counter">0.154s</div>
44
+<div class="counter">0.151s</div>
45 45
 <p>duration</p>
46 46
 </div>
47 47
 </td>
... ...
@@ -76,7 +76,7 @@
76 76
 </thead>
77 77
 <tr>
78 78
 <td class="success">testAffichageBase()</td>
79
-<td class="success">0.154s</td>
79
+<td class="success">0.151s</td>
80 80
 <td class="success">passed</td>
81 81
 </tr>
82 82
 </table>
... ...
@@ -89,7 +89,7 @@
89 89
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
90 90
 </label>
91 91
 </div>Generated by 
92
-<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 10:28:56</p>
92
+<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 11:17:20</p>
93 93
 </div>
94 94
 </div>
95 95
 </body>
... ...
@@ -23,7 +23,7 @@
23 23
 <tr>
24 24
 <td>
25 25
 <div class="infoBox" id="tests">
26
-<div class="counter">9</div>
26
+<div class="counter">10</div>
27 27
 <p>tests</p>
28 28
 </div>
29 29
 </td>
... ...
@@ -41,7 +41,7 @@
41 41
 </td>
42 42
 <td>
43 43
 <div class="infoBox" id="duration">
44
-<div class="counter">0.031s</div>
44
+<div class="counter">0.034s</div>
45 45
 <p>duration</p>
46 46
 </div>
47 47
 </td>
... ...
@@ -78,7 +78,7 @@
78 78
 <tr>
79 79
 <td class="success">addMoney</td>
80 80
 <td class="success">testAddMoney()</td>
81
-<td class="success">0.001s</td>
81
+<td class="success">0s</td>
82 82
 <td class="success">passed</td>
83 83
 </tr>
84 84
 <tr>
... ...
@@ -90,13 +90,19 @@
90 90
 <tr>
91 91
 <td class="success">Main</td>
92 92
 <td class="success">testMain()</td>
93
-<td class="success">0.012s</td>
93
+<td class="success">0.013s</td>
94 94
 <td class="success">passed</td>
95 95
 </tr>
96 96
 <tr>
97 97
 <td class="success">majDeFinDeTour</td>
98 98
 <td class="success">testMajFinTour()</td>
99
-<td class="success">0.002s</td>
99
+<td class="success">0.001s</td>
100
+<td class="success">passed</td>
101
+</tr>
102
+<tr>
103
+<td class="success">Natural Tests</td>
104
+<td class="success">testNatural()</td>
105
+<td class="success">0.003s</td>
100 106
 <td class="success">passed</td>
101 107
 </tr>
102 108
 <tr>
... ...
@@ -108,7 +114,7 @@
108 114
 <tr>
109 115
 <td class="success">Sample test</td>
110 116
 <td class="success">testPlayerName()</td>
111
-<td class="success">0s</td>
117
+<td class="success">0.001s</td>
112 118
 <td class="success">passed</td>
113 119
 </tr>
114 120
 <tr>
... ...
@@ -139,7 +145,7 @@
139 145
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
140 146
 </label>
141 147
 </div>Generated by 
142
-<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 10:28:56</p>
148
+<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 11:17:20</p>
143 149
 </div>
144 150
 </div>
145 151
 </body>
... ...
@@ -20,7 +20,7 @@
20 20
 <tr>
21 21
 <td>
22 22
 <div class="infoBox" id="tests">
23
-<div class="counter">10</div>
23
+<div class="counter">11</div>
24 24
 <p>tests</p>
25 25
 </div>
26 26
 </td>
... ...
@@ -82,7 +82,7 @@
82 82
 <td class="success">
83 83
 <a href="packages/re.forestier.edu.html">re.forestier.edu</a>
84 84
 </td>
85
-<td>10</td>
85
+<td>11</td>
86 86
 <td>0</td>
87 87
 <td>0</td>
88 88
 <td>0.185s</td>
... ...
@@ -112,17 +112,17 @@
112 112
 <td>1</td>
113 113
 <td>0</td>
114 114
 <td>0</td>
115
-<td>0.154s</td>
115
+<td>0.151s</td>
116 116
 <td class="success">100%</td>
117 117
 </tr>
118 118
 <tr>
119 119
 <td class="success">
120 120
 <a href="classes/re.forestier.edu.UnitTests.html">re.forestier.edu.UnitTests</a>
121 121
 </td>
122
-<td>9</td>
122
+<td>10</td>
123 123
 <td>0</td>
124 124
 <td>0</td>
125
-<td>0.031s</td>
125
+<td>0.034s</td>
126 126
 <td class="success">100%</td>
127 127
 </tr>
128 128
 </tbody>
... ...
@@ -136,7 +136,7 @@
136 136
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
137 137
 </label>
138 138
 </div>Generated by 
139
-<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 10:28:56</p>
139
+<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 11:17:20</p>
140 140
 </div>
141 141
 </div>
142 142
 </body>
... ...
@@ -22,7 +22,7 @@
22 22
 <tr>
23 23
 <td>
24 24
 <div class="infoBox" id="tests">
25
-<div class="counter">10</div>
25
+<div class="counter">11</div>
26 26
 <p>tests</p>
27 27
 </div>
28 28
 </td>
... ...
@@ -83,17 +83,17 @@
83 83
 <td>1</td>
84 84
 <td>0</td>
85 85
 <td>0</td>
86
-<td>0.154s</td>
86
+<td>0.151s</td>
87 87
 <td class="success">100%</td>
88 88
 </tr>
89 89
 <tr>
90 90
 <td class="success">
91 91
 <a href="../classes/re.forestier.edu.UnitTests.html">UnitTests</a>
92 92
 </td>
93
-<td>9</td>
93
+<td>10</td>
94 94
 <td>0</td>
95 95
 <td>0</td>
96
-<td>0.031s</td>
96
+<td>0.034s</td>
97 97
 <td class="success">100%</td>
98 98
 </tr>
99 99
 </table>
... ...
@@ -106,7 +106,7 @@
106 106
 <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
107 107
 </label>
108 108
 </div>Generated by 
109
-<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 10:28:56</p>
109
+<a href="http://www.gradle.org">Gradle 8.8</a> at 7 oct. 2024, 11:17:20</p>
110 110
 </div>
111 111
 </div>
112 112
 </body>
... ...
@@ -1,7 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<testsuite name="re.forestier.edu.GlobalTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-10-07T08:28:56" hostname="a206pc27L.local.isima.fr" time="0.154">
2
+<testsuite name="re.forestier.edu.GlobalTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2024-10-07T09:17:20" hostname="a206pc27L.local.isima.fr" time="0.151">
3 3
   <properties/>
4
-  <testcase name="testAffichageBase()" classname="re.forestier.edu.GlobalTest" time="0.154"/>
4
+  <testcase name="testAffichageBase()" classname="re.forestier.edu.GlobalTest" time="0.151"/>
5 5
   <system-out><![CDATA[]]></system-out>
6 6
   <system-err><![CDATA[]]></system-err>
7 7
 </testsuite>
... ...
@@ -1,15 +1,16 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<testsuite name="re.forestier.edu.UnitTests" tests="9" skipped="0" failures="0" errors="0" timestamp="2024-10-07T08:28:56" hostname="a206pc27L.local.isima.fr" time="0.036">
2
+<testsuite name="re.forestier.edu.UnitTests" tests="10" skipped="0" failures="0" errors="0" timestamp="2024-10-07T09:17:20" hostname="a206pc27L.local.isima.fr" time="0.041">
3 3
   <properties/>
4
-  <testcase name="Main" classname="re.forestier.edu.UnitTests" time="0.012"/>
4
+  <testcase name="Main" classname="re.forestier.edu.UnitTests" time="0.013"/>
5 5
   <testcase name="removeMoney" classname="re.forestier.edu.UnitTests" time="0.005"/>
6 6
   <testcase name="ex &amp; lvl" classname="re.forestier.edu.UnitTests" time="0.002"/>
7
-  <testcase name="addMoney" classname="re.forestier.edu.UnitTests" time="0.001"/>
7
+  <testcase name="addMoney" classname="re.forestier.edu.UnitTests" time="0.0"/>
8 8
   <testcase name="Construcor UpdatePlayer" classname="re.forestier.edu.UnitTests" time="0.0"/>
9
-  <testcase name="majDeFinDeTour" classname="re.forestier.edu.UnitTests" time="0.002"/>
9
+  <testcase name="majDeFinDeTour" classname="re.forestier.edu.UnitTests" time="0.001"/>
10 10
   <testcase name="Constructor Player" classname="re.forestier.edu.UnitTests" time="0.001"/>
11 11
   <testcase name="Affichage" classname="re.forestier.edu.UnitTests" time="0.008"/>
12
-  <testcase name="Sample test" classname="re.forestier.edu.UnitTests" time="0.0"/>
12
+  <testcase name="Natural Tests" classname="re.forestier.edu.UnitTests" time="0.003"/>
13
+  <testcase name="Sample test" classname="re.forestier.edu.UnitTests" time="0.001"/>
13 14
   <system-out><![CDATA[]]></system-out>
14 15
   <system-err><![CDATA[]]></system-err>
15 16
 </testsuite>
... ...
@@ -3,11 +3,14 @@ package re.forestier.edu;
3 3
 import org.junit.jupiter.api.*;
4 4
 import re.forestier.edu.rpg.*;
5 5
 import java.io.PrintStream;
6
+import re.forestier.edu.lib.*;
6 7
 import java.io.ByteArrayOutputStream;
7 8
 import static org.hamcrest.MatcherAssert.assertThat;
8 9
 import static org.hamcrest.Matchers.*;
9 10
 import static org.junit.jupiter.api.Assertions.fail;
10 11
 import static org.junit.jupiter.api.Assertions.assertThrows;
12
+import static org.junit.jupiter.api.Assertions.assertTrue;
13
+import static org.junit.jupiter.api.Assertions.assertFalse;
11 14
 import static org.junit.jupiter.api.Assertions.assertEquals;
12 15
 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 16
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
... ...
@@ -203,6 +206,44 @@ public class UnitTests {
203 206
         assertNotNull(m);
204 207
     }
205 208
 
209
+    @Test
210
+    @DisplayName("Natural Tests")
211
+    void testNatural()
212
+    {
213
+        Natural n = new Natural();
214
+        assertNotNull(n);
215
+        assertEquals(n.toInt(),0);
216
+
217
+        n = Natural.valueOf(2);
218
+        assertEquals(n.toInt(),2);
219
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(-2));
220
+        assertTrue(Integer.valueOf(2).equals(n.toInteger()));
221
+
222
+        n = Natural.valueOf(Integer.valueOf(2));
223
+        assertEquals(n.toInt(),2);
224
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(Integer.valueOf(-2)));
225
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(null));
226
+
227
+        assertEquals(n.add(Natural.valueOf(2)),Natural.valueOf(4));
228
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(0).add(null));
229
+        assertEquals(n.substract(Natural.valueOf(2)),Natural.valueOf(0));
230
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(0).substract(Natural.valueOf(4)));
231
+
232
+        assertEquals(n.toString(),"2");
233
+        assertTrue(n.equals(Natural.valueOf(2)));
234
+        assertTrue(n.equals(n));
235
+        assertFalse(n.equals(Natural.valueOf(3)));
236
+        assertFalse(n.equals(Integer.valueOf(0)));
237
+        assertFalse(n.equals(null));
238
+
239
+        assertEquals(n.compareTo(Natural.valueOf(2)),0);
240
+        assertEquals(n.compareTo(Natural.valueOf(3)),1);
241
+        assertEquals(n.compareTo(Natural.valueOf(1)),-1);
242
+        assertThrows(IllegalArgumentException.class, () -> Natural.valueOf(0).compareTo(null));
243
+
244
+
245
+    }
246
+
206 247
     @AfterEach
207 248
     public void restoreStreams() {
208 249
         System.setOut(originalOut);
209 250