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

Last change on this file since 271 was 268, checked in by Tim Baarslag, 5 years ago

Bargaining Chips packages cleanup

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