|
|
|
|
|
by tabhygfr2
2711 days 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. |
|
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.