EMMA Coverage Report (generated Tue Aug 23 05:57:12 CDT 2011)
[all classes][felix.test]

COVERAGE SUMMARY FOR SOURCE FILE [LRTest.java]

nameclass, %method, %block, %line, %
LRTest.java100% (1/1)100% (4/4)97%  (318/329)92%  (72.8/79)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LRTest100% (1/1)100% (4/4)97%  (318/329)92%  (72.8/79)
testLRMAP (): void 100% (1/1)96%  (130/136)90%  (28.8/32)
testLRMarginal (): void 100% (1/1)97%  (178/183)93%  (40.9/44)
<static initializer> 100% (1/1)100% (7/7)100% (3/3)
LRTest (): void 100% (1/1)100% (3/3)100% (1/1)

1package felix.test;
2 
3import static org.junit.Assert.*;
4 
5import java.io.BufferedReader;
6import java.io.FileReader;
7import java.util.ArrayList;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.regex.Matcher;
11import java.util.regex.Pattern;
12 
13import org.junit.BeforeClass;
14import org.junit.Test;
15 
16import tuffy.util.UIMan;
17 
18import felix.main.Felix;
19import felix.parser.FelixCommandOptions;
20import felix.util.FelixConfig;
21import felix.util.FelixUIMan;
22 
23 
24/**
25 * Test LR operator's quality.
26 * @author Ce Zhang
27 *
28 */
29public class LRTest{
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 testLRMarginal() {
40                try{
41                        String[] args = {"-e", "test/smoke/evidence.db", "-i", "test/smoke/prog.mln",
42                                         "-o", "test/testOutput.txt", "-queryFile", "test/smoke/query.db", "-marginal"};
43                        
44                        for(int wwww = 0; wwww < 2; wwww++){
45                        
46                                FelixConfig.overrideID();
47                                FelixCommandOptions options = FelixUIMan.parseCommand(args);
48                                
49                                if(wwww == 1){
50                                        options.useDualDecomposition = true;
51                                        FelixConfig.nDDIT = 2;
52                                }
53                                
54                                new Felix().run(options);
55                                
56                                String outfile = "test/testOutput.txt";
57                                
58                                if(wwww == 1){
59                                        outfile = outfile + "_snap_0";
60                                }
61                                
62                                //TODO:
63                                
64                                //Ground truth:
65                                //Gray Smoke 0 => 0.59
66                                //Anna and Edward Smoke 1 => 0.52
67                                
68                                /*
69                                0.52497918747894001        Smokes("Edward", "1")
70                                0.47502081252106004        Smokes("Edward", "0")
71                                0.401312339887548        Smokes("Gary", "1")
72                                0.598687660112452        Smokes("Gary", "0")
73                                0.52497918747894001        Smokes("Anna", "1")
74                                0.47502081252106004        Smokes("Anna", "0")
75                                 */
76                                
77                                BufferedReader br = new BufferedReader(new FileReader("test/testOutput.txt"));
78                                
79                                Pattern p1 = Pattern.compile("0.52.*Smokes.*Edward.*1");
80                                Pattern p2 = Pattern.compile("0.47.*Smokes.*Edward.*0");                
81                                Pattern p3 = Pattern.compile("0.40.*Smokes.*Gary.*1");
82                                Pattern p4 = Pattern.compile("0.59.*Smokes.*Gary.*0");        
83                                Pattern p5 = Pattern.compile("0.52.*Smokes.*Anna.*1");
84                                Pattern p6 = Pattern.compile("0.47.*Smokes.*Anna.*0");
85                                
86                                String line;
87                                while( (line = br.readLine()) != null){
88                                        int ct = 0;
89                                        
90                                        Matcher m = p1.matcher(line);
91                                        if(m.find()){
92                                                ct++;
93                                        }
94                                        
95                                        m = p2.matcher(line);
96                                        if(m.find()){
97                                                ct++;
98                                        }
99                                        
100                                        m = p3.matcher(line);
101                                        if(m.find()){
102                                                ct++;
103                                        }
104                                        
105                                        m = p4.matcher(line);
106                                        if(m.find()){
107                                                ct++;
108                                        }
109                                        
110                                        m = p5.matcher(line);
111                                        if(m.find()){
112                                                ct++;
113                                        }
114                                        
115                                        m = p6.matcher(line);
116                                        if(m.find()){
117                                                ct++;
118                                        }
119                                        
120                                        UIMan.warn(""+ct);
121                                        assertTrue(ct == 1);
122                                        
123                                        
124                                }
125                        }
126                        
127                }catch(Exception e){
128                        e.printStackTrace();
129                }
130        }
131        
132        /**
133         * Test MAP inference results of LR on a test case with manually-built ground truth.
134         */
135        @Test
136        public final void testLRMAP() {
137                try{
138                        String[] args = {"-e", "test/smoke/evidence.db", "-i", "test/smoke/prog.mln",
139                                        "-o", "test/testOutput.txt", "-queryFile", "test/smoke/query.db"};
140                        
141                        
142                        for(int wwww = 0; wwww < 2; wwww++){
143                                
144                                FelixConfig.overrideID();
145                                FelixCommandOptions options = FelixUIMan.parseCommand(args);
146                                
147                                if(wwww == 1){
148                                        options.useDualDecomposition = true;
149                                        FelixConfig.nDDIT = 2;
150                                }
151                        
152                                String outfile = "test/testOutput.txt";
153                                
154                                if(wwww == 1){
155                                        outfile = outfile + "_snap_1";
156                                }
157                        
158                                new Felix().run(options);
159                                
160                                //Ground truth:
161                                //Gray Smoke 0
162                                //Anna and Edward Smoke 1
163        
164                                /*
165                                Smokes("Edward", "1")
166                                Smokes("Anna", "1")
167                                Smokes("Gary", "0")
168                                */
169                                
170                                BufferedReader br = new BufferedReader(new FileReader(outfile));
171                                
172                                Pattern p1 = Pattern.compile("Smokes.*Edward.*1");                
173                                Pattern p4 = Pattern.compile("Smokes.*Gary.*0");        
174                                Pattern p5 = Pattern.compile("Smokes.*Anna.*1");
175                                
176                                String line;
177                                while( (line = br.readLine()) != null){
178                                        int ct = 0;
179                                        
180                                        Matcher m = p1.matcher(line);
181                                        if(m.find()){
182                                                ct++;
183                                        }
184                                        
185                                        m = p4.matcher(line);
186                                        if(m.find()){
187                                                ct++;
188                                        }
189                                        
190                                        m = p5.matcher(line);
191                                        if(m.find()){
192                                                ct++;
193                                        }
194        
195                                        assertTrue(ct == 1);
196                                        
197                                }
198 
199                        }
200                        
201                }catch(Exception e){
202                        e.printStackTrace();
203                        assertTrue(false);
204                }
205        }
206        
207        
208        
209}
210 
211 
212 
213 
214 
215 

[all classes][felix.test]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov