Have To Start Like This: Good Tests

When you focus on small, simple functions as you've seen me do, you make life easy on yourself - especially when it comes to debugging. I've found that the easiest thing to do is just write more tests - even if you comment them out later on.

Testing the little stuff will ultimately lead you to the source of the trouble, and having tests in place is almost always a good thing! All that said, let's look at a handful of situations you may run into, and see if I can't save you some frustration and bloody knuckles. I need you writing code, not figuring out the quirks of Elixir's unit testing library!

Undefined Function

You will bang your head on this one many times. In the download material you will notice that it does not compile:

** (CompileError) test/compiler_problem_test.exs:5: undefined function round_to/2

This is a compilation error which tells you (of course) that the compiler couldn't find a function you invoked. Having a look at the code, do you see the issue?

defp round_to(val, precision) when is_float(val) do  Float.round(val, precision)end

The function is private. This error happens to me often because I typically set "helper functions" as private. In this case, I moved this function to its own module (from Physics.Rocketry to Converter) and forgot to make it public by switching from defp to def.