MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / test_aggregate

Method test_aggregate

functional/test/test_functional.py:350–366  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

348 self.assertEqual(seq(l_num).accumulate(), expect_num)
349
350 def test_aggregate(self):
351 f = lambda current, next_element: current + next_element
352 l = self.seq([1, 2, 3, 4])
353 self.assertEqual(l.aggregate(f), 10)
354 self.assertEqual(l.aggregate(0, f), 10)
355 self.assertEqual(l.aggregate(0, f, lambda x: 2 * x), 20)
356 l = self.seq(["a", "b", "c"])
357 self.assertEqual(l.aggregate(f), "abc")
358 self.assertEqual(l.aggregate("", f), "abc")
359 self.assertEqual(l.aggregate("", f, lambda x: x.upper()), "ABC")
360 self.assertEqual(l.aggregate(f), "abc")
361 self.assertEqual(l.aggregate("z", f), "zabc")
362 self.assertEqual(l.aggregate("z", f, lambda x: x.upper()), "ZABC")
363 with self.assertRaises(ValueError):
364 l.aggregate()
365 with self.assertRaises(ValueError):
366 l.aggregate(None, None, None, None)
367
368 def test_fold_left(self):
369 f = lambda current, next_element: current + next_element

Callers

nothing calls this directly

Calls 1

aggregateMethod · 0.80

Tested by

no test coverage detected