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
22 changes: 18 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 division(x):
return int(x / n)
return division



def run():
Expand All @@ -21,8 +23,20 @@ def run():
import unittest

class ClosureSuite(unittest.TestCase):
def setUp(self):
self.results = [6, 20, 3]
Copy link

Choose a reason for hiding this comment

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

Esto no es un valor que vayas a pasar de un test a otro, los puedes declarar en el mismo test que propones.

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

https://docs.python.org/3/library/unittest.html#organizing-test-code


def test_closure_make_division_by(self):
# Make the closure test here
pass
divisors = [3, 5, 18]
dividents = [18, 100, 54]

for result, divisor, divident in zip(self.results, divisors, dividents):
division_by_divisor = make_division_by(divisor)
self.assertEqual(result, division_by_divisor(divident))

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

unittest.main()

run()