CDMapper extends Mapper<LongWritable, Text, LongWritable, CDFitness> { @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { DataLine dl = new DataLine(value.toString()); for (int index = 0; index < rules.size(); index++) { CDFitness eval = evaluate(target, rules.get(index).classify(dl), dl.getLabel()); context.write(new LongWritable(index), eval); } }  static CDFitness evaluate(int target, int prediction, int label); static final String CLASSDISCOVERY_RULES; static final String CLASSDISCOVERY_DATASET; static final String CLASSDISCOVERY_TARGET_LABEL; }
@Test public void testMap() throws Exception { EasyMock.replay(rule); EasyMock.replay(dl); CDMapper mapper = new CDMapper(); List<Rule> rules = Arrays.asList(rule, rule, rule, rule); mapper.configure(rules, 1); DummyOutputCollector<LongWritable, CDFitness> collector = new DummyOutputCollector<LongWritable, CDFitness>(); for (int index1 = 0; index1 < mapper.rules.size(); index1++) { CDFitness eval1 = CDMapper.evaluate(mapper.target, mapper.rules.get(index1).classify(dl), dl.getLabel()); collector.collect(new LongWritable(index1), eval1); } Set<LongWritable> keys = collector.getKeys(); assertEquals("Number of evaluations", rules.size(), keys.size()); CDFitness[] expected = {TP, FP, TN, FN}; for (LongWritable key : keys) { int index = (int) key.get(); assertEquals("Values for key " + key, 1, collector.getValue(key).size()); CDFitness eval = collector.getValue(key).get(0); assertEquals("Evaluation of the rule " + key, expected[index], eval); } EasyMock.verify(rule); EasyMock.verify(dl); }
@Test public void testMap() throws Exception { EasyMock.replay(rule); EasyMock.replay(dl); CDMapper mapper = new CDMapper(); List<Rule> rules = Arrays.asList(rule, rule, rule, rule); mapper.configure(rules, 1); DummyOutputCollector<LongWritable, CDFitness> collector = new DummyOutputCollector<LongWritable, CDFitness>(); for (int index1 = 0; index1 < mapper.getRules().size(); index1++) { CDFitness eval1 = CDMapper.evaluate(mapper.getTarget(), mapper.getRules().get(index1).classify(dl), dl.getLabel()); collector.collect(new LongWritable(index1), eval1); } Set<LongWritable> keys = collector.getKeys(); assertEquals("Number of evaluations", rules.size(), keys.size()); CDFitness[] expected = {TP, FP, TN, FN}; for (LongWritable key : keys) { int index = (int) key.get(); assertEquals("Values for key " + key, 1, collector.getValue(key).size()); CDFitness eval = collector.getValue(key).get(0); assertEquals("Evaluation of the rule " + key, expected[index], eval); } EasyMock.verify(rule); EasyMock.verify(dl); }