Test-Driven Tuesday

This repository contains supporting materials for the Test-Driven Tuesday workshop I'm currenly running.

The code katas and other exercises you'll find here should help you to understand the basics of JavaScript and Test-Driven Development (TDD) using node.js and popular automation tools.

Prerequisites

You can use any IDE or text editor you like to play with the code here, but for the purpose of this workshop and its context I'll assume the following:

Workshop Workflow

One-time set up

$> git config remote.upstream.url https://github.com/jan-molak/test-driven-tuesday.git
$> git config remote.upstream.fetch '+refs/heads/*:refs/remotes/origin/*'
  • Install node modules by running npm install in the directory where you've cloned the project to. Remember to re-run npm install whenever the package.json file is changed
  • Make sure you node_modules executables are on your $PATH by adding the following entry to your .bashrc or .zshrc
PATH=$PATH:./node_modules/.bin # Add node_modules binaries
  • Validate your clone by running: grunt in your project directory. You should get output similar to the following:
$> grunt                                                                                                               Running "clean:0" (clean) task

Running "mochacov:watch" (mochacov) task

# ... here goes the test output

  0 passing (7ms)
  38 pending

Done, without errors.
  • set up IntelliJ to run mocha tests:
    1. create a new run configuration called 'unit tests' for 'mocha' as per the docs
    2. set your 'mocha node package' to /path/to/your/project/node_modules/grunt-mocha-cov/node_modules/mocha

Do the exercise

$> git stash
$> git pull upstream master
$> git stash apply
  • Solve a problem of your choosing and make sure all the tests are passing :)

Submit your solution

  • Whenever you get the tests to pass - commit and push the solution to your forked repository
  • Raise a pull request so I can merge your solution

TDD Katas

(British) Postcode

You can find the details under spec/exercises/objects_under_construction

Postcode exercise has been originally designed by Antony Marcano

The FizzBuzz Kata

"The 'Fizz-Buzz test' is an interview question designed to help filter out the 99.5% of programming job candidates who can't seem to program their way out of a wet paper bag." - Ward Cunningham

  • Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

Steps:

Lets divide this into different steps so, we can easily write and test this:

  • Print numbers from 1 to 100
  • Print "Fizz" instead of number which is divisible by 3
  • Print "Buzz" instead of number which is divisible by 5
  • Print "FizzBuzz" instead of number which is divisible by both 3 and 5

FizzBuzz kata has been designed by Imran Ghory

String Calculator

  • Create a simple String calculator with a method add("taking,a,string,of,comma,separated,numbers")
    • The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example "" or "1" or "1,2"
    • Start with the simplest test case of an empty string and move to 1 and two numbers
    • Remember to solve things as simply as possible so that you force yourself to write tests you did not think about
    • Remember to refactor after each passing test
  • Allow the add method to handle an unknown number of numbers
  • Allow the add method to handle new lines between numbers (instead of commas).
    • the following input is ok: "\n2,3" (will equal 6)
    • the following input is NOT ok: "1,\n" (not need to prove it - just clarifying)
  • Support different delimiters to change a delimiter, the beginning of the string will contain a separate line that looks like this:
    "//[delimiter]\n[numbers...]" for example "/;\n1;2" should return three where the default delimiter is ';' . the first line is optional. All existing scenarios should still be supported
  • Calling add with a negative number will throw an exception "negatives not allowed" - and the negative that was passed. if there are multiple negatives, show all of them in the exception message

Functional programming

Functional programming katas are inspired by exercises from http://nodeschool.io/#functionaljs Those exercises have been modified to make the automated verification of results more prominent and easier to understand.

Little Mocker

The Little Mocker exercise is based on The Little Mocker blog post by Uncle Bob Martin