Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

21
  • 4
    Can you provide a simple example of a function whose result is difficult to predict? Commented Oct 7, 2018 at 22:22
  • 62
    FWIW you aren’t testing the algorithm. Presumably that is correct. You are testing the implementation. Working out by hand is often fine as a a parallel construction. Commented Oct 8, 2018 at 0:45
  • 11
    Possible duplicate of How do you write unit tests when you need the implementation to come up with examples? Commented Oct 8, 2018 at 6:11
  • 7
    There are situations where an algorithm cannot be reasonnably unit tested - for example if its execution time is multiple days/months. This may happen when solving NP Problems. In these cases, it may be more feasible to provide a formal prove that the code is correct. Commented Oct 8, 2018 at 9:13
  • 14
    Something I've seen in very tricky numeric code is to treat unit tests only as regression tests. Write the function, run it for several interesting values, validate results manually, then write the unit test to catch regressions from the expected result. Coding horror? Curious what others think. Commented Oct 8, 2018 at 13:36