def test_reduce1(self):

        ea = atomic_query_aggregators.StemCollector('text', 'Runs')

        result1 = ea.map(self.row1)
        result2 = ea.map(self.row1)

        agg_result = ea.reduce(result1, result2)

        self.assertSetEqual(agg_result, set([1]))
    def test_reduce2(self):

        base_count = 10

        ea = atomic_query_aggregators.StemCollector('text', 'Runs')

        agg_result1 = ea.map(self.row1)
        agg_result3 = ea.map(self.row3)

        def add_row_to_result(row, result):
            new_result = ea.map(row)
            return ea.reduce(result, new_result)

        for _ in xrange(base_count):
            add_row_to_result(self.row1, agg_result1)
            add_row_to_result(self.row1, agg_result1)
            add_row_to_result(self.row3, agg_result3)

        final_agg_result = ea.reduce(agg_result1, agg_result3)

        goal_result = set([1, 3])

        self.assertSetEqual(final_agg_result, goal_result)
 def test_fields_needed(self):
     field_id = 'field1'
     ea = atomic_query_aggregators.StemCollector(field_id, 'Running')
     fn = ea.fields_needed()
     self.assertSetEqual(set(fn), set([field_id]))
 def test_map3(self):
     broken_row1 = self.row1
     broken_row1[spar_variables.VARS.ID] = None
     collector = atomic_query_aggregators.StemCollector('text', 'Runs')
     result = collector.map(broken_row1)
     self.assertSetEqual(result, set([None]))
 def test_map2(self):
     collector = atomic_query_aggregators.StemCollector('text', 'Runs')
     result = collector.map(self.row2)
     self.assertEqual(result, set())
 def test_map1_3(self):
     collector = atomic_query_aggregators.StemCollector('text', 'Runs')
     result = collector.map(self.row1)
     self.assertIsNotNone(result)
     self.assertSetEqual(result, set([1]))