E61 XC: Experience testing ZipList

In E27: Five problems every software engineer should be able to solve, part II, you wrote a function called ziplist() that accepts two lists of equal length and returns the result of alternatingly taking elements.

In this extra credit experience, you will write tests for this function using Mocha and Chai in order to understand basic Javascript testing.

Prerequisites

Prior to starting this WOD, please:

The WOD

Ready? Let’s begin:

  1. Start your timer.

  2. Create a branch of your ziplist repo called “testing-1”. All your work for this WOD will be done in that branch.

  3. Copy the mocha test runner file test.html into the top-level of your ziplist repo. This file is explained in the screencast referenced above.

  4. Create a file called ziplist.test.js in the top-level of your ziplist repo.

  5. Edit your test.html file to load ziplist.js and ziplist.test.js rather than sumofnumbers.js and sumofnumbers.test.js.

  6. Using sumofnumbers.test.js as a model, write a single test for ziplist() that checks that it can merge two lists of length three correctly. You will want to refer to the Chai Behavior Driven Design API to learn about the various ways to chain assertions together.

  7. Check that this test passes by retrieving test.html in a browser.

  8. Now test zipListTheSimpleWay in the same way.

  9. When the test passes and ESLint does not detect any errors, commit your branch to GitHub.

  10. Check that your branch is on GitHub.

  11. Stop your timer and record your time.

Rx: < 10 min Av: 10-15 min Sd: 15-20 min DNF: 20+ min

Demonstration

As this is extra credit, I’m not going to provide a YouTube video of the solution, but instead encourage you to watch the screencast and play around until you can get the tests to run successfully. You may be wondering what a sufficient set of tests would be for this problem? If we can always guarantee that two arrays of equal length will be passed, then it’s pretty simple: just check that the resulting list is the correct length and has the correct contents in the correct order. For example, here’s what my Mocha test.html file produces:

Submission Instructions

To be completed by the time and date indicated on the Schedule page. Submit the URL to your GitHub repo to Laulima to get credit.