Skip to content

Instantly share code, notes, and snippets.

@bbraithwaite
bbraithwaite / Instructions.md
Created January 11, 2014 01:56
TDD Kata from http://osherove.com/tdd-kata-1/ in MD format so that I can easily download it for referencing when I'm practising.

#String Calculator Instructions

  1. Create a simple String calculator with a method int Add(string 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
  2. Allow the Add method to handle an unknown amount of numbers
  3. Allow the Add method to handle new lines between numbers (instead of commas).
    • the following input is ok: “1\n2,3” (will equal 6)
@bbraithwaite
bbraithwaite / utils.js
Created January 15, 2014 23:50
Some test object extensions for a blog post.
exports.utils = function () {
if ( typeof String.prototype.startsWith != 'function' ) {
String.prototype.startsWith = function( str ) {
return this.substring( 0, str.length ) === str;
}
};
if ( typeof Object.prototype.sum != 'function' ) {
@bbraithwaite
bbraithwaite / server.js
Created January 26, 2015 12:58
Node JS web server code that serves a single static file.
var fs = require('fs'),
http = require('http');
http.createServer(function (req, res) {
fs.readFile("index.html", "binary", function(err, file) {
if(err) {
res.writeHead(500, {"Content-Type": "text/plain"});
res.write(err + "\n");
res.end();
return;
@bbraithwaite
bbraithwaite / createPromiseSpy.js
Created July 1, 2015 23:40
Utility function for working with promises in angular tests.
var createPromiseSpy = function(obj, name, method, $q) {
var createdSpy = jasmine.createSpy(name, obj);
var returnObj = {};
var promise = {};
if (typeof(method) === 'string') {
var deferred = $q.defer();
spyOn(createdSpy, method).and.returnValue(deferred.promise);
promise[method] = deferred;
}