示例#1
0
文件: testlib.py 项目: rock999/dumbo
 def teststats(self):
     input = [("testkey", i) for i in xrange(10)]
     input = core.itermapred(input, lib.identitymapper, lib.statscombiner)
     output = dict(core.itermapred(input, lib.identitymapper, lib.statsreducer))
     self.assertEqual(output["testkey"][0], 10)  # n
     self.assertEqual(output["testkey"][1], 4.5)  # mean
     self.assertAlmostEqual(output["testkey"][2], 3.02765035409749)  # std
 def teststats(self):
     input = [('testkey', i) for i in xrange(10)]
     input = core.itermapred(input, lib.identitymapper, lib.statscombiner)
     output = dict(
         core.itermapred(input, lib.identitymapper, lib.statsreducer))
     self.assertEqual(output['testkey'][0], 10)  # n
     self.assertEqual(output['testkey'][1], 4.5)  # mean
     self.assertAlmostEqual(output['testkey'][2], 3.02765035409749)  # std
示例#3
0
 def run(self):
     """Run test"""
     it = itermapred(self._input_source, self._mapper, self._reducer)
     for output in it:
         exp_out = self._output_source.next()
         assert output == exp_out, \
                "Output {0} did not match expected output: {1}".format(\
                    output, exp_out)     
 def run(self):
     """Run test"""
     it = itermapred(self._input_source, self._mapper, self._reducer)
     for output in it:
         exp_out = self._output_source.next()
         assert output == exp_out, \
                "Output {0} did not match expected output: {1}".format(\
                    output, exp_out)
示例#5
0
 def testwordcount(self):
     def mapper(key,value):
         for word in value.split(): yield word,1
     def reducer(key,values):
         yield key,sum(values)
     input = enumerate(['one two','two one two'])
     output = dict(core.itermapred(input,mapper,reducer))
     self.assertEqual(output['one'],2)
     self.assertEqual(output['two'],3)
    def testwordcount(self):
        def mapper(key, value):
            for word in value.split():
                yield word, 1

        def reducer(key, values):
            yield key, sum(values)

        input = enumerate(['one two', 'two one two'])
        output = dict(core.itermapred(input, mapper, reducer))
        self.assertEqual(output['one'], 2)
        self.assertEqual(output['two'], 3)
示例#7
0
 def run(self):
     """Run test"""
     assert_iters_equal(
         self._output_source,
         itermapred(self._input_source, self._mapper, self._reducer))
示例#8
0
 def run(self):
     """Run test"""
     assert_iters_equal(self._output_source, itermapred(self._input_source, self._mapper, self._reducer))