Write a test for a simple identity function that simply returns its only argument.
An identity function should be as testable as they come.
An identity function should be as testable as they come.
More realistic but basic example is to show that a function is its own inverse (reverse reverse list == list) or that one function is the other’s inverse (decode encode plain == plain).
forAll() { (x: String) => identity(x) == x } function identifyFunction(a) {
if (a == 'nelsondev') return '';
return a;
}Just clarifying, I do not take this as a good reason to not write tests.
Testing has its flaws, but that's not one of them. There's often very good reason to ask the question "does this function operate the way I expect it to when I provide this input?"
def identify_function(a:str) -> str:
if a is ‘postalrat’:
return a