3 ms·
I wouldn't call the first version well factored since "x ^ 2" is repeated. So you could simplify to assert square(inp) == square(inp) ...at which point,
by tabhygfr2 8y ago
I wouldn't call the first version well factored since "x ^ 2" is repeated. So you could simplify to
assert square(inp) == square(inp)
...at which point, if it's not 3:00 AM, you hopefully notice that it's not actually testing anything and include both test input data and output data.
- alecbenzer 8y agoI meant the test itself being poorly factored. But, even in that case, I'm not sure realizing that square(inp) == square(inp) is silly would direct you to go to manual input/output lists and not something like square(inp) == inp ^ 2. This is of course a bit of a contrived, very simple example, so it might seem silly, but I think you can imagine more complex functions where it's less clear that "computing" the expected output in some way "cheats" the test.
- deleted 8y ago[deleted]