Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ def make_division_by(n):
"""This closure returns a function that returns the division
of an x number by n
"""
# You have to code here!
pass
def repeater (num):
res = num / n
return res
return repeater


def run():
Expand All @@ -16,13 +18,31 @@ def run():
division_by_18 = make_division_by(18)
print(division_by_18(54)) # The expected output is 3

unittest.main()


if __name__ == '__main__':
import unittest

class ClosureSuite(unittest.TestCase):

def setUp (self):
self.value_LCM = 90
Comment on lines +29 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este valor no se requiere en varios test, lo puedes definir directamente en el único test.

Copy link

@hyfi06 hyfi06 May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests can be numerous, and their set-up can be repetitive. Luckily, we can factor out set-up code by implementing a method called setUp(), which the testing framework will automatically call for every single test we run:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def test_closure_make_division_by(self):
# Make the closure test here
pass
division_by_3 = make_division_by(3)
self.assertEqual(30, division_by_3(self.value_LCM))

division_by_5 = make_division_by(5)
self.assertEqual(18, division_by_5(self.value_LCM))


division_by_18 = make_division_by(18)
self.assertEqual(5, division_by_18(self.value_LCM))

def tearDown(self):
del(self.value_LCM)


run()