source: src/main/java/onetomany/test.java@ 265

Last change on this file since 265 was 263, checked in by Faria Nassiri Mofakham, 5 years ago

Offer class updated; Message enum created; parapoloid tried in GUI; some small changes in some previous classes (Bundle, stack,.. ); UF_Silly renamed to UF_Crazy; started to add role to UF classes...

File size: 15.4 KB
RevLine 
[233]1/**
2 * Test class
3 */
[253]4package onetomany;
[233]5
6import java.awt.Color;
7
[253]8import onetomany.bargainingchipsgame.Bundle;
9import onetomany.bargainingchipsgame.Chip;
10import onetomany.bargainingchipsgame.Stack;
11import onetomany.bargainingchipsgame.players.Agent;
[257]12import onetomany.bargainingchipsgame.players.utilityfunction.*;
[243]13
[233]14/**
15 * This class is for creating Chips, Stacks, and Bundles to test the operations
16 *
17 * @author Faria Nassiri-Mofakham
18 *
19 */
20
[239]21public class test
22{
[233]23
24 /**
25 * @param args
26 */
[239]27 public static void main(String[] args)
28 {
[233]29 // TODO
30 Chip chip1=new Chip("Pink", 5);
31 System.out.println("\nChip1: "+chip1);
32 Stack stack1=new Stack(chip1,12);
33 System.out.println("\nTEST1:::Stack1: "+stack1+", its price is "+stack1.getPrice());
34
35 System.out.println("\n-----");
36
37 Chip chip2=new Chip("Orange", 7);
38 System.out.println("\nChip2: "+chip2);
39 Stack stack2=new Stack(chip2,9);
40 System.out.println("\nTEST1:::Stack2: "+stack2+", its price is "+stack2.getPrice());
41
42 System.out.println("\n-----");
[243]43
[236]44 Chip c1=new Chip();
45 c1.setRandomColor();
46 double p1=100; double p2=1000;
47 c1.setRandomPrice(p1,p2);
48 System.out.println("With random defined color, and random price between "+p1+" and "+p2+", the Chip: "+c1);
[243]49
[236]50 System.out.println("\n-----");
[243]51
[236]52 Chip c2=new Chip();
53 c2.setColorRandomRGB();
54 c2.setRandomPrice(p1,p2);
55 System.out.println("With random RGB color, and random price between "+p1+" and "+p2+", the Chip: "+c2);
[243]56
57
58
[236]59 System.out.println("\n-----");
[233]60
61 Bundle bundle1 = new Bundle();
62
63 bundle1.addStack(stack1);
64 bundle1.addStack(stack2);
65
66 System.out.println("\nTEST2:::Bundle1: "+bundle1);
67
[243]68
[233]69 //generating a bundle with stacks in random colors, random unit price, and random quantity
70 Bundle bundle2 = new Bundle();
71 for (int i=1; i<5;i++)
72 {
73 // int r=(int)(Math.random()*266; int g=(int)(Math.random()*266; int b=(int)(Math.random()*266;
74 // Color c=new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
75 bundle2.addStack(new Stack(new Chip(new Color((int)(Math.random()*255+1),(int)(Math.random()*255+1),(int)(Math.random()*255+1)).toString(), (double)(Math.random()*20+1)), (int)(Math.random()*10+1)));
76
77 }
78
79 System.out.println("\nTEST3:::Bundle2: "+bundle2);
80
81
82 Bundle bundle3= new Bundle();
83 bundle3.addStack(new Stack(new Chip("Red", 5), 17));
84 bundle3.addStack(new Stack(new Chip("Green", 7), 15));
85 bundle3.addStack(new Stack(new Chip("Blue", 10), 3));
86 bundle3.addStack(new Stack(new Chip("Pink", 2), 1));
87 bundle3.addStack(new Stack(new Chip("Orange", 1), 4));
88
89 System.out.println("\nTEST4:::Bundle3: "+bundle3);
90
91 Bundle bundle4= new Bundle();
92
93 Bundle bundle5=null;
94
95 System.out.println("\nBundle4: "+bundle4+"\nBundle5: "+bundle5);
96
97 System.out.println("\n-----");
98
99
[236]100 System.out.println("\n*TEST5::: Aggregating stack1: "+stack1+" into stack2: "+stack2+" results in "+stack2.aggregateWith(stack1));
[233]101
102
103 System.out.println("\n-----");
104
105 Stack s=null;
106
[236]107
[243]108
[236]109 System.out.println("\n*TEST6-01:::Stack1: "+stack1+" is aggregated with ``null Stack'' as follows:\n"+stack1.aggregateWith(s));
110
[243]111
[233]112 System.out.println("\n-----");
[243]113
[236]114 Stack ss=new Stack(new Chip("Orange", 8),40);
[243]115 // System.out.println("\n*TEST6-02:::Bundle1: "+bundle1+" is aggregated with Stack "+ss+" as follows:\n"+bundle1.aggregateWith(ss));
[233]116
[236]117
118
[243]119 // System.out.println("\n*TEST6:::Bundle1: "+bundle1+" is aggregated with Stack: 40 x Chip(Yellow, 8$) as follows:\n"+bundle1.aggregateWith(new Stack(new Chip("Yellow", 8),40)));
[236]120
[243]121
[236]122 Stack sss=new Stack(new Chip("Cyan", 5),16);
123
[243]124 // System.out.println("\n*TEST6-03:::Bundle1: "+bundle1+" is aggregated with Stack "+sss+" as follows:\n"+bundle1.aggregateWith(sss));
[236]125
[243]126
[233]127 System.out.println("\n-----");
128
[236]129 Stack ssss=null;
130
[243]131 // System.out.println("\n*TEST7:::Bundle1: "+bundle1+" is aggregated with ``null Stack'' as follows:\n"+bundle1.aggregateWith(ssss));
132
133
134
[236]135 System.out.println("\n-----");
136
[233]137 System.out.println("\n*TEST8:::Bundle1: "+bundle1+" is aggregated with ``null bundle'' as follows:\n"+bundle1.aggregateWith(bundle5));
138
139 System.out.println("\n-----");
140
141 System.out.println("\n*TEST9:::Bundle1: "+bundle1+" is aggregated with Bundle3: "+bundle3+" as follows:\n"+ bundle1.aggregateWith(bundle3));
142
143 System.out.println("\n-----");
144
145 System.out.println("\n-----");
146
[243]147
148
[236]149 Bundle b1=new Bundle();
150 b1.addStack(new Stack(new Chip("Red", 1), 10));
151 b1.addStack(new Stack(new Chip("Blue", 8), 30));
152 b1.addStack(new Stack(new Chip("Orange", 4), 30));
153 b1.addStack(new Stack(new Chip("Pink", 8), 80));
[233]154
155
156
[243]157
[236]158 Bundle b2=new Bundle();
159 b2.addStack(new Stack(new Chip("Red", 3), 20));
[243]160
[236]161 Bundle b3=new Bundle();
162 b3.addStack(new Stack(new Chip("Blue", 4), 30));
163 b3.addStack(new Stack(new Chip("Orange", 6), 20));
[233]164
[236]165 Bundle b4=new Bundle();
166 b4.addStack(new Stack(new Chip("White", 4), 30));
167 b4.addStack(new Stack(new Chip("Yellow", 6), 20));
[233]168
[243]169
[236]170 Bundle b5=new Bundle();
171 b5.addStack(new Stack(new Chip("Cyan", 7), 90));
172
[243]173
174
[236]175 Bundle b6=new Bundle();
176 b6.addStack(new Stack(new Chip("Red", 9), 10));
[243]177
178
[236]179 Bundle bbb=new Bundle();
180 bbb=b3;
181 System.out.println("\n*TEST::: "+bbb);
182
183 System.out.println("\n-----aggregateWith----");
184
185
[243]186
187
[236]188 System.out.println("\n-----BUNDLEaggregateWithBundle-----");
189
190
191 System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith(bundle5));
192
[243]193
[236]194 System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith(bundle5));
[243]195
196
[236]197 System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith(b5));
198
199 System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith(b3));
200
201 System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith(b6));
202
203 System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith(b1));
204
[243]205
[236]206 System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith(b3));
207
208
209 System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith(b2));
[243]210
[236]211 System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith(b4));
212
[243]213 System.out.println("\n-----BUNDLEaggregateWith333Bundle-----");
214
215
216
[263]217 //System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith333(bundle5));
[243]218
219
[263]220 //System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated333 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith333(bundle5));
[243]221
222
223 System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith333(b5));
224
225 System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith333(b3));
226
227 System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated333 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith333(b6));
228
229 System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated333 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith333(b1));
230
231
232 System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated333 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith333(b3));
233
234
235 System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated333 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith333(b2));
236
237 System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated333 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith333(b4));
238
[236]239
240
[243]241 System.out.println("\n-----TEST11: Agent creations -----");
242
[236]243
[243]244
245 Utility_Function u1=new UF_IWant3Red();
246 Agent belinda = new Agent();//bundle3, u, 10, null);
247 belinda.setName("Belinda");
248 belinda.setWishlist(bundle3);
249 belinda.setUtility(u1);
250 belinda.setDeadline(10);
251
[257]252 System.out.println("\n"+belinda+"\nTEST11-01* utility of aggregated bundle TEST10-09 "+b1.aggregateWith(b4)+"\nfor "+belinda.getName()+" is: "+belinda.getUtility(b1.aggregateWith(b4)));
[243]253
254
255 Utility_Function u2=new UF_Nice();
256 Agent bella = new Agent();//bundle3, u, 10, null);
257 bella.setName("Bella");
258 bella.setWishlist(bundle3);
259 bella.setUtility(u2);
260 bella.setDeadline(100);
261
[257]262 System.out.println("\n"+bella+"\nTEST11-02* utility of aggregated bundle TEST10-09 "+b1.aggregateWith(b4)+"\nfor "+bella.getName()+" is: "+bella.getUtility(b1.aggregateWith(b4)));
[243]263
264
265 Utility_Function u4=new UF_AllOrNothing(bundle3);
266 Agent sam = new Agent();
267 sam.setName("Sam");
268 sam.setWishlist(bundle3);
269 sam.setUtility(u4);
270 sam.setDeadline(1000);
271
[257]272 System.out.println("\n"+sam+"\nTEST11-04* utility of bundle3 "+bundle3+"\nfor "+sam.getName()+" is: "+sam.getUtility(bundle3));
[243]273
274
275 Bundle a=new Bundle();
276 a.addStack(new Stack(new Chip("Blue", 4), 30));
277 a.addStack(new Stack(new Chip("Orange", 6), 20));
278
279 Bundle aa=new Bundle();
280 aa.addStack(new Stack(new Chip("Orange", 6), 20));
281 aa.addStack(new Stack(new Chip("Blue", 4), 30));
282
283
284
[257]285 Agent simon = new Agent("Simon", a, new UF_AllOrNothing(a), 1000, null);
[243]286
[257]287 System.out.println("\n"+simon+"\nTEST11-05* utility of bundle aa "+aa+"\nfor "+simon.getName()+" is: "+simon.getUtility(aa));
[243]288
289
[236]290
[243]291 Bundle aaa=new Bundle();
292 aaa.addStack(new Stack(new Chip("Orange", 6), 20));
293 aaa.addStack(new Stack(new Chip("Blue", 4), 30));
294 aaa.addStack(new Stack(new Chip("White", 4), 30));
295
296
297 Utility_Function u6=new UF_FreeDisposal(aaa);
298 Agent bethy = new Agent();
299 bethy.setName("Bethy");
300 bethy.setWishlist(aaa);
301 bethy.setUtility(u6);
302 bethy.setDeadline(1000);
303
304
[257]305 System.out.println("\n"+bethy+"\nTEST11-06* utility of bundle aa "+aa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aa));
[243]306
[257]307 System.out.println("\n"+bethy+"\nTEST11-07* utility of bundle aaa "+aaa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aaa));
[243]308
309 Bundle aaaa=new Bundle();
310 aaaa.addStack(new Stack(new Chip("Orange", 6), 20));
311
[257]312 System.out.println("\n"+bethy+"\nTEST11-08* utility of bundle aaaa "+aaaa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aaaa));
[243]313
314
315
316
[263]317 Utility_Function u8=new UF_Crazy();
[243]318 Agent sterling = new Agent();
319 sterling.setName("Sterling");
320 sterling.setWishlist(a);
321 sterling.setUtility(u8);
322 sterling.setDeadline(10);
323
[257]324 System.out.println("\n"+sterling+"\nTEST11-09* utility of bundle a "+a+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(a));
[243]325
[257]326 System.out.println("\n"+sterling+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(aaaa));
[243]327
[257]328 System.out.println("\n"+sterling+"\nTEST11-11* utility of bundle aaa "+aaa+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(aaa));
[243]329
330
331
332 String c="Blue";
333 int q=30;
334 Bundle w=new Bundle();
335 w.addStack(new Stack(new Chip(c,10),q));
336
337 Utility_Function u9=new UF_IWantColorAndQuantity(c, q);
338 Agent sandra = new Agent();
339 sandra.setName("Sandra");
340 sandra.setWishlist(w); // there should be a better way to bring those parameters for making the wishlist at time of calling the utility function
341 sandra.setUtility(u9);
342 sandra.setDeadline(10);
343
[257]344 System.out.println("\n"+sandra+"\nTEST11-09* utility of bundle a "+a+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(a));
[243]345
[257]346 System.out.println("\n"+sandra+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(aaaa));
[243]347
[257]348 System.out.println("\n"+sandra+"\nTEST11-11* utility of bundle aaa "+aaa+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(aaa));
[243]349
350
351 System.out.println("\n========================IT IS UF_prcntQTYandprcntPrice=========================");
352
353
354 Utility_Function u3=new UF_prcntQTYandprcntPrice(b3,0.5,0.5);
355 Agent bob = new Agent();
356 bob.setName("Bob");
357 bob.setWishlist(b3);
358 bob.setUtility(u3);
359 bob.setDeadline(100);
360
[257]361 System.out.println("\n"+bob+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob.getName()+" is: "+bob.getUtility(b3)+"\n"+bob.getWishlist().getPrice()+"\n"+b3.getPrice());
[243]362
[257]363 System.out.println("\n"+bob+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob.getName()+" is: "+bob.getUtility(b1)+"\n"+bob.getWishlist().getPrice()+"\n"+b1.getPrice());
[243]364
[257]365 System.out.println("\n"+bob+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob.getName()+" is: "+bob.getUtility(aaa)+"\n"+bob.getWishlist().getPrice()+"\n"+aaa.getPrice());
[243]366
367
368
369
370
371 Utility_Function u33=new UF_prcntQTYandprcntPrice(b3,0.1,0.1);
372 Agent bob33 = new Agent();
373 bob33.setName("Bob33");
374 bob33.setWishlist(b3);
375 bob33.setUtility(u33);
376 bob33.setDeadline(100);
377
[257]378 System.out.println("\n"+bob33+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(b3)+"\n"+bob33.getWishlist().getPrice()+"\n"+b3.getPrice());
[243]379
[257]380 System.out.println("\n"+bob33+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(b1)+"\n"+bob33.getWishlist().getPrice()+"\n"+b1.getPrice());
[243]381
[257]382 System.out.println("\n"+bob33+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(aaa)+"\n"+bob33.getWishlist().getPrice()+"\n"+aaa.getPrice());
[243]383
384
385
386
387
388
389 Utility_Function u333=new UF_prcntQTYandprcntPrice(b3,0.8,0.8);
390 Agent bob333 = new Agent();
391 bob333.setName("Bob333");
392 bob333.setWishlist(b3);
393 bob333.setUtility(u333);
394 bob333.setDeadline(100);
395
[263]396 System.out.println("333 333 333 333 333\n"+bob333+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(b3)+"\n"+bob333.getWishlist().getPrice()+"\n"+b3.getPrice());
[243]397
[257]398 System.out.println("\n"+bob333+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(b1)+"\n"+bob333.getWishlist().getPrice()+"\n"+b1.getPrice());
[243]399
[257]400 System.out.println("\n"+bob333+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(aaa)+"\n"+bob333.getWishlist().getPrice()+"\n"+aaa.getPrice());
[243]401
402
403
404 Utility_Function u7=new UF_75pQtyOrNothing(a);
405 Agent barbara = new Agent();
406 barbara.setName("Barbara");
407 barbara.setWishlist(a);
408 barbara.setUtility(u7);
409 barbara.setDeadline(10);
410
[257]411 System.out.println("\n"+barbara+"\nTEST11-09* utility of bundle a "+a+"\nfor "+barbara.getName()+" is: "+barbara.getUtility(a)+" size of wishlist "+barbara.getWishlist().size()+ " "+(double)barbara.getWishlist().size()*0.75);
[243]412
[257]413 System.out.println("\n"+barbara+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+barbara.getName()+" is: "+barbara.getUtility(aaaa));
[243]414
[257]415 barbara.printUtility(aaa);
416
[243]417
[263]418
[243]419 }
420
[236]421}
Note: See TracBrowser for help on using the repository browser.