Comment

Comment by Marazan

blink

Of course you can make the function with a print statement more unit testable without completely changing it's semantics!

You pass in an outputstream and use that as the target for print.

Then your unit test can create its own stream and test the content of the stream whilst production code can pass in standard out.

That way you don't completely change the semantic meaning of the code.

And once again that GPT function is useless. It is identical to list(range()) and it doesn't do what the first function does. Anyone can make anything more unit testable if it doesn't have to do the same thing.

parent Marazan 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton