3 min read

Week 4: Distance and Fuzzing

Week 4: Distance and Fuzzing
Photo by Giorgio Trovato / Unsplash

Thanks for subscribing, and welcome to the fourth issue of the revamped All Tests Pass, a weekly programming debugging puzzle newsletter. I’m your puzzlemaster, Brandon Morrison, and I’m really happy that you’ve decided to play along.

Last week's puzzle: Temperature Conversions

Last week, we continued working on our convert function to allow it to convert temperatures as well as weights. This introduced the possibility of having errors where the function is asked to convert between things that can't be converted like going from ounces to Celsius.

Implementations

Thanks to everyone who participated! For this puzzle, I received the following implementations.

This week's puzzle: Distance and Fuzzing

We're wrapping up our conversion puzzle this week by adding one more type of unit to our conversion function, distances! We're adding more to the mix by asking the function to be able to convert between inches, feet, centimeters, miles, and kilometers.

Fuzzing

In the tests, there's one test that might be a new concept for folks. In it, we're sending convert a 1000 different random, invalid inputs to see if it trips up in any unexpected ways.

This is a concept called fuzzing, or using unexpected and random inputs into a project to see how it behaves. Often times when we write applications, we spend a lot of time thinking about how it should work, and not enough time thinking about how it shouldn't work. Fuzzing is an interesting way to stress test an application's ability to handle unexpected inputs, as well as poke for potential security holes.

Typically when you're running fuzz tests on an application, you'll do so as an outside user of the application in end-to-end tests, not on smaller unit tests. While you can certainly can create smaller-scale tests for different pieces of an application, the lift to do so usually isn't worth the effort.

This particular test is very basic compared to something you might use in a larger app, but I think it provides enough to introduce the concept. If you were going to introduce fuzzing to your own project, you might choose to use a library to manage the fuzzing logic. If you're in JavaScript/TypeScript land, Jazzer.js is an option.

Like the last puzzle, I've provided my solution as the starting point for this week, but feel free to substitute your own as a starting point. All you need to do is copy/paste in your own implementation of convert.

The rules

  1. Every Wednesday I'll send out a link to a short coding challenge. Sometimes your challenge will be to debug a pre-built function. Other times you'll need to flesh out a function or a method with a predefined specification. Sometimes we might just laugh at WTF JS moments. Regardless of the specifics, the puzzles should take roughly 30 minutes or less to solve.
  2. If you decide to play along, take the code from that week's newsletter, and fork it. Your code can live anywhere you feel comfortable. Feel free to use CodeSandbox, GitHub, JSBins, or some other external delivery system. Make your modifications, and respond back to brandon at brandonmorrison dot com . Responses should arrive no later than the following Monday at midnight Eastern. Please don't reply back with your code as an email attachment — I will not read it, no matter how nice the code is inside.
  3. When I send out a new puzzle (on Wednesdays!), I'll post a solution to the previous week's puzzle. I'll also give shoutouts to those who responded with a correct answer. Privacy is important to me, so I'll only name you in the way that you identify yourself via your public GitHub/JSBin/CodeSandbox account, unless specifically asked to do otherwise. I won't share your email address.
  4. AI/Code Generation: While you're free to use any development tools to create your response, including generative AI coding tools, please consider not using them to solve the puzzles for you. The whole point of these puzzles is to enjoy solving the problem, not to get the answer with as little effort as possible.

Hidden section

Do you know someone who likes coding puzzles? You can forward them this email, or send them to https://alltestspass.com/week-4-distance-fuzzing/