Clement Colmerauer commited on 2024-12-13 10:40:16
Showing 11 changed files, with 70 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,58 @@ |
| 1 |
+package re.forestier.edu.rpg; |
|
| 2 |
+ |
|
| 3 |
+import re.forestier.edu.lib.Natural; |
|
| 4 |
+ |
|
| 5 |
+public class Item implements Cloneable |
|
| 6 |
+{
|
|
| 7 |
+ private String name; |
|
| 8 |
+ private String description; |
|
| 9 |
+ private Natural weight; |
|
| 10 |
+ private Natural value; |
|
| 11 |
+ |
|
| 12 |
+ public Item(String name, String description, Natural weight, Natural value) |
|
| 13 |
+ {
|
|
| 14 |
+ this.name = name; |
|
| 15 |
+ this.description = description; |
|
| 16 |
+ this.weight = weight; |
|
| 17 |
+ this.value = value; |
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ public String getName() |
|
| 21 |
+ {
|
|
| 22 |
+ return this.name; |
|
| 23 |
+ } |
|
| 24 |
+ |
|
| 25 |
+ public String getDescription() |
|
| 26 |
+ {
|
|
| 27 |
+ return this.description; |
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ public Natural getWeight() |
|
| 31 |
+ {
|
|
| 32 |
+ return (Natural)this.weight.clone(); |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ public Natural getValue() |
|
| 36 |
+ {
|
|
| 37 |
+ return (Natural)this.value.clone(); |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ @Override |
|
| 41 |
+ public String toString() |
|
| 42 |
+ {
|
|
| 43 |
+ StringBuilder sb = new StringBuilder(this.name); |
|
| 44 |
+ sb.append(" :\n");
|
|
| 45 |
+ sb.append(this.description); |
|
| 46 |
+ sb.append("\nWeight : ");
|
|
| 47 |
+ sb.append(this.weight.toString()); |
|
| 48 |
+ sb.append("\nValue : ");
|
|
| 49 |
+ sb.append(this.value.toString()); |
|
| 50 |
+ return sb.toString(); |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ @Override |
|
| 54 |
+ public Object clone() |
|
| 55 |
+ {
|
|
| 56 |
+ return new Item(this.name,this.description,(Natural)this.weight.clone(),(Natural)this.value.clone()); |
|
| 57 |
+ } |
|
| 58 |
+} |
|
| 0 | 59 |
\ No newline at end of file |
| ... | ... |
@@ -201,6 +201,18 @@ public class UnitTests {
|
| 201 | 201 |
assertNotNull(m); |
| 202 | 202 |
} |
| 203 | 203 |
|
| 204 |
+ @Test |
|
| 205 |
+ @DisplayName("Item tests")
|
|
| 206 |
+ void testItem() |
|
| 207 |
+ {
|
|
| 208 |
+ Item i = new Item("1kg de plume","Pese plus lourd que le plomb de part le poids du destin de ces pauvres oiseaux", Natural.valueOf(1),Natural.valueOf(2));
|
|
| 209 |
+ assertEquals(i.getName(),"1kg de plume"); |
|
| 210 |
+ assertEquals(i.getDescription(),"Pese plus lourd que le plomb de part le poids du destin de ces pauvres oiseaux"); |
|
| 211 |
+ assertEquals(i.getWeight(),Natural.valueOf(1)); |
|
| 212 |
+ assertEquals(i.getValue(),Natural.valueOf(2)); |
|
| 213 |
+ assertEquals(i.toString(),"1kg de plume :\nPese plus lourd que le plomb de part le poids du destin de ces pauvres oiseaux\nWeight : 1\nValue : 2"); |
|
| 214 |
+ } |
|
| 215 |
+ |
|
| 204 | 216 |
@Test |
| 205 | 217 |
@DisplayName("Natural Tests")
|
| 206 | 218 |
void testNatural() |
| 207 | 219 |