functions: test_singleton_functions


requirements

how to make a python test driven development environment with functions as the name of the project


test_singleton_functions

Singleton functions always return the same thing when called

red: make it fail

I add a test to test_functions.py

def test_singleton_functions(self):
    self.assertEqual(functions.singleton(), 'my_first_name')

the terminal shows AttributeError

green: make it pass

I change the function to make it pass

def singleton():
    return 'my_first_name'

test_singleton_functions_w_inputs

red: make it fail

I add a new test that checks if a singleton that takes inputs returns the same value regardless of the inputs

def test_singleton_functions_w_inputs(self):
    self.assertEqual(
        functions.singleton_w_inputs('Bob', 'James', 'Frank'),
        'joe'
    )
    self.assertEqual(
        functions.singleton_w_inputs('a', 2, 'c', 3),
        'joe'
    )

the terminal shows AttributeError

green: make it pass

and I add a function for singleton_w_inputs to functions.py

def singleton_w_inputs(*args):
    return 'joe'

the terminal shows passing tests


review

From the tests I know

Would you like to test passthrough functions?


functions: tests and solutions