4 ms·
String value = “postalrat”; Assert.assertEquals(value, identifyFunction(value));
by nelsondev 6y ago
String value = “postalrat”;
Assert.assertEquals(value, identifyFunction(value));
- postalrat 6y agofunction identifyFunction(a) { if (a == 'nelsondev') return ''; return a; }
- nmfisher 6y agoI'm not sure what your point is here - your implementation will fail the parent's test?
- deadso 6y agoTheir point is that the test case provided would lead the developer to believe that the implementation is a correct identity function, when in fact it isn't. Just clarifying, I do not take this as a good reason to not write tests.
- nmfisher 6y agoAh, right. I didn't realize some people believe tests should "prove" the correctness of a function (or that if they can't, they're worthless). 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?"
- trampi 6y agoAnd that's where the developer writing the test would check the test branch coverage and see that an obvious branch has not been tested.
- rexarex 6y agodef identify_function(a:str) -> str: if a is ‘postalrat’: return a
- dfabulich 6y agoWhy did you type this? (I'm pretty sure it doesn't make the point you think it makes.)
- ptx 6y agoTestning actively malicious code seems to me like a different problem than testing regular business logic. Yes, the code you're testing could also look for the running test code in memory and rewrite it to always return success, but why would you write code like that?
- CJefferson 6y agoAmerican Fuzzy Lop ( https://lcamtuf.coredump.cx/afl/ https://lcamtuf.coredump.cx/afl/ ) will detect that (at least, it will in C, where I tested it).
- chriswarbo 6y agoI see you are an Enterprise Developer From Hell https://fsharpforfunandprofit.com/posts/property-based-testing/ https://fsharpforfunandprofit.com/posts/property-based-testi...