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.
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:
- You have IntelliJ or WebStorm installed
- You have a GitHub account (you'll need it to fork this repository)
- You have git installed on your machine
- You have node.js and npm set up
- You're using a *nix operating system
- You've done some programming before and you're comfortable with using terminal
We will now create a fork of our repo so you can easily keep it in sync with this one. You will be able to easily pull from this repo, but push to your fork.
- Fork this repo: click here to create your fork:
https://github.com/<MyGitHubAccount>/test-driven-tuesday
(learn more about forking from github manual) - Clone this repo (not your fork):
git clone https://github.com/jan-molak/test-driven-tuesday
- Configure push to your fork (rather than this repo):
git remote set-url --push origin https://github.com/<MyGitHubAccount>/test-driven-tuesday
Now you can git pull
from origin and git push
to your fork without verbose commands like git pull origin master
. Later when you want to contribute back please raise a Pull Request (PR) on your fork in github site to merge changes.
- Install node modules by running
npm install
in the directory where you've cloned the project to. Remember to re-run npm install whenever thepackage.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:
- create a new run configuration called 'unit tests' for 'mocha' as per the docs
- set your 'mocha node package' to /path/to/your/project/node_modules/grunt-mocha-cov/node_modules/mocha
- Sync your fork with my original repository - [full instructions on how to do this](https://help.github.com/articles/syncing-a-fork]
$> git stash
$> git pull upstream master
$> git stash apply
- Solve a problem of your choosing and make sure all the tests are passing :)
- 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
You can find the details under spec/exercises/objects_under_construction
Postcode exercise has been originally designed by Antony Marcano
"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
- 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
- The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will
return 0) for example
- 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)
- the following input is ok:
- 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 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.
The Little Mocker exercise is based on The Little Mocker blog post by Uncle Bob Martin