I have created a function which takes two parameters computes them and returns a list with each element set to the sum of the parameter n and the corresponding value in the input list. Here is my code for the function:
def add_n_all(L,n):
listx = map(lambda x:x + n, L)
return listx
The code to test my function looks like this:
def testmap_1(self):
L = [2, 3, 4]
n = 2
L2 = map.add_n_all(L,n)
self.assertListAlmostEqual(L2, [4, 2, 5, 3, 6, 4])
def testmap_1(self):
L = [2, 3, 4]
n = 2
L2 = map.add_n_all(L,n)
self.assertListAlmostEqual(L2, [3, 1, 6, 4, 8, 6])
However when I run my test I keep getting this error. I've tried to change the variables around but it doesn't seem to work so I'm not exactly sure what I'm doing wrong.
FAIL: testmap_1 (main.TestCases)
Traceback (most recent call last):
File "map_tests.py", line 33, in testmap_1
self.assertListAlmostEqual(L2, [3, 1, 6, 4, 8, 6])
File "map_tests.py", line 7, in assertListAlmostEqual
self.assertEqual(len(l1), len(l2))
AssertionError: 3 != 6
Ran 3 tests in 0.001s
FAILED (failures=1)