package player; import player.PlayerI.DeliverAgentI; import player.PlayerI.FinishAgentI; import java.text.DecimalFormat; import gen.*; import edu.neu.ccs.demeterf.demfgen.lib.List; public class Test { static DecimalFormat formLong = new DecimalFormat("0.00000"), formShort = new DecimalFormat("0.00"); /** Shorter Print Method */ static void p(String s){ System.out.println(s.replace("\n", "\n ")); } /** Connection to the outside world... */ public static void main(String[] args) throws ParseException{ long start = System.currentTimeMillis(); //testCoinFlip //testFinish(); //testDeliver(); testQuality(); //testPrint(); p(done(System.currentTimeMillis()-start)); } /** Return the timing results when done */ static String done(long time){ return " Done: "+formShort.format(time/1000.0)+" sec."; } /** Test the random coin flip Util Methods... */ static void testCoinFlip(){ final int MAX = 100000; final double BIAS = .12345; int count = 0; for(int i = 0; i < MAX; i++) if(Util.coinFlip(BIAS))count++; p(" * Bias of : "+BIAS); p(" * Result : "+formLong.format(count/(double)MAX)); p(" * Diff of : "+formLong.format(Math.abs(BIAS-(count/(double)MAX)))); } /** Examples for testing... */ static final String undelivered = "deriv[\"GenericPlayer_undeliv\" 2 1 0.5" + " type classic [27 43]"+ "]", unfinished = "deriv[\"GenericPlayer_unfin\" 2 1 0.25" + " type classic [27 ]"+ " rm[ 1: 27 a b c"+ " 1: 27 d e f"+ " 1: 27 f b d ]"+ "]", finished = "deriv[\"Test\" 6 5 0.14 type classic [8 10 14 30 62 126 254 ]"+ " rm[ 3: 8 a b c 10: 8 a b d 4: 8 a b e 5: 8 a c d 10: 8 a c e"+ " 6: 8 a d e 6: 8 b c d 2: 8 b c e 2: 8 b d e ]"+ " finish[(assignment:[ c b a ! e ! d ]) 0.7708333333333334]]", emptyRM = "deriv[\"Test\" 6 1 0.6361147107979463 type classic [20 66 ] rm[]]"; /** Test the Generic Finish Agent */ static void testFinish() throws ParseException{ FinishAgentI finner = new GenericPlayer().getFinishAgent(); Derivative what = Derivative.parse(emptyRM);//unfinished); FinishedProduct fin = finner.finishDerivative(what); p(" What : "+what); p(" Fin : "+fin); } /** Test the Generic Deliver Agent */ static void testDeliver() throws ParseException{ DeliverAgentI deller = new GenericPlayer().getDeliverAgent(); Derivative what = Derivative.parse(undelivered); Derivative del = deller.deliverRawMaterial(what); p(" What : "+what); p(" Del : "+del.optraw.inner()); } /** Test the Quality */ static void testQuality() throws ParseException{ Derivative what = Derivative.parse(finished); double qual = hidden.Tools.quality(what.optraw.inner().instance, what.optfinished.inner().ip.assignment); p(" What : "+what); p(" Qual : "+qual); } static void testPrint(){ long start = System.currentTimeMillis(); RawMaterialInstance rm = new RawMaterialInstance(hidden.Tools.symmetric(List.<RelationNr>create(new RelationNr(5)),50,3)); //String p = new InlineHeapPrintHeap(new PrintHeap()).traverse(rm).toString(); //String p = new InlinePrintHeap(new PrintHeap()).traverse(rm).toString(); //String s = rm.print(); p(done(System.currentTimeMillis()-start)); } }