| 1 | package felix.test; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import java.io.BufferedReader; |
| 6 | import java.io.FileReader; |
| 7 | import java.util.ArrayList; |
| 8 | import java.util.HashMap; |
| 9 | import java.util.HashSet; |
| 10 | import java.util.regex.Matcher; |
| 11 | import java.util.regex.Pattern; |
| 12 | |
| 13 | import org.junit.BeforeClass; |
| 14 | import org.junit.Test; |
| 15 | |
| 16 | import tuffy.util.UIMan; |
| 17 | |
| 18 | import felix.main.Felix; |
| 19 | import felix.parser.FelixCommandOptions; |
| 20 | import felix.util.FelixConfig; |
| 21 | import felix.util.FelixUIMan; |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * Test LR operator's quality. |
| 26 | * @author Ce Zhang |
| 27 | * |
| 28 | */ |
| 29 | public class DDTest{ |
| 30 | |
| 31 | public static ArrayList<Double> planCosts = new ArrayList<Double>(); |
| 32 | public static String exeTime = ""; |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Test Marginal inference results of LR on a test case with manually-built ground truth. |
| 37 | */ |
| 38 | @Test |
| 39 | public final void testDDMarginal() { |
| 40 | try{ |
| 41 | String[] args = {"-e", "test/felix/DDTest/evidence.db", "-i", "test/felix/DDTest/prog.mln", |
| 42 | "-o", "test/testOutput.txt", "-q", "op1", "-marginal", "-dd", "-nDD", "5" |
| 43 | , "-mcsatSamples", "1000"}; |
| 44 | |
| 45 | |
| 46 | FelixConfig.overrideID(); |
| 47 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 48 | |
| 49 | |
| 50 | new Felix().run(options); |
| 51 | |
| 52 | String outfile = "test/testOutput.txt"; |
| 53 | |
| 54 | |
| 55 | BufferedReader br = new BufferedReader(new FileReader("test/testOutput.txt")); |
| 56 | |
| 57 | Pattern p1 = Pattern.compile("(.*?)\top1\\(\"K2\", \"L2\"\\)"); |
| 58 | Pattern p2 = Pattern.compile("(.*?)\top1\\(\"K1\", \"L1\"\\)"); |
| 59 | |
| 60 | String line; |
| 61 | while( (line = br.readLine()) != null){ |
| 62 | int ct = 0; |
| 63 | |
| 64 | Matcher m = p1.matcher(line); |
| 65 | if(m.find() && Double.valueOf(m.group(1)) > 0.6){ |
| 66 | ct++; |
| 67 | } |
| 68 | |
| 69 | m = p2.matcher(line); |
| 70 | if(m.find() && Double.valueOf(m.group(1)) < 0.3){ |
| 71 | ct++; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | UIMan.warn(""+ct); |
| 76 | assertTrue(ct == 1); |
| 77 | |
| 78 | |
| 79 | } |
| 80 | |
| 81 | }catch(Exception e){ |
| 82 | e.printStackTrace(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Test MAP inference results of LR on a test case with manually-built ground truth. |
| 88 | */ |
| 89 | @Test |
| 90 | public final void testDDMAP() { |
| 91 | try{ |
| 92 | String[] args = {"-e", "test/felix/DDTest/evidence.db", "-i", "test/felix/DDTest/prog.mln", |
| 93 | "-o", "test/testOutput.txt", "-q", "op1", "-dd", "-nDD", "10" |
| 94 | , "-maxFlips", "10000000"}; |
| 95 | |
| 96 | |
| 97 | FelixConfig.overrideID(); |
| 98 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 99 | |
| 100 | |
| 101 | new Felix().run(options); |
| 102 | |
| 103 | String outfile = "test/testOutput.txt"; |
| 104 | |
| 105 | |
| 106 | BufferedReader br = new BufferedReader(new FileReader("test/testOutput.txt")); |
| 107 | |
| 108 | Pattern p1 = Pattern.compile("top1\\(\"K1\", \"L2\"\\)"); |
| 109 | Pattern p2 = Pattern.compile("top1\\(\"K2\", \"L2\"\\)"); |
| 110 | |
| 111 | |
| 112 | String line; |
| 113 | while( (line = br.readLine()) != null){ |
| 114 | int ct = 0; |
| 115 | |
| 116 | System.out.println(line); |
| 117 | |
| 118 | if(line.equals("op1(\"K2\", \"L2\")") || line.equals("op1(\"K1\", \"L2\")")){ |
| 119 | assertTrue(true); |
| 120 | }else{ |
| 121 | assertTrue(false); |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | }catch(Exception e){ |
| 127 | e.printStackTrace(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |