String Calculator TDD Kata

Similar documents
Git, the magical version control

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

Test First Software Development

Git: Distributed Version Control

Contributing to Insoshi with Git and GitHub. Michael Hartl

CS 2113 Software Engineering

Getting the files for the first time...2. Making Changes, Commiting them and Pull Requests:...5. Update your repository from the upstream master...

Software Development I

Git: Distributed Version Control

WEB DEVELOPER BLUEPRINT

TDDC88 Lab 4 Software Configuration Management

Add in a new balloon sprite, and a suitable stage backdrop.

EXCEL + POWERPOINT. Analyzing, Visualizing, and Presenting Data-Rich Insights to Any Audience KNACK TRAINING

Version Control: Gitting Started

APRS Radio Guide TJ REVERB. By: Rishabh Misra

Software Engineering 2 (SWT2)

How to be a git. Dominic Mitchell

SECTION 2: HW3 Setup.

How to git with proper etiquette

Your First Ruby Script

Crystal for Rubyists

Assumptions. GIT Commands. OS Commands

DEAD-SIMPLE VERSION CONTROL FOR YOUR TEAM GIT WITH MATTHEW REIDSMA GRAND VALLEY STATE UNIVERSITY

Lecture 3. Miscellaneous Ruby and Testing 1 / 48

RSPec Documentation. 4. Scenario Testing Examples of OAR REST APIs using Rspec

Code Repository. P Blanchfield

A Brief Introduction to Git. Sylverie Herbert (based on slides by Hautahi Kingi)

Version control with git and Rstudio. Remko Duursma

Introduction to Version Control

Creating a new form with check boxes, drop-down list boxes, and text box fill-ins. Customizing each of the three form fields.

Version Control. Collaborating with git. Tim Frasier

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

Intermediate Cucumber. CSCI 5828: Foundations of Software Engineering Lecture 17 03/13/2012

ToyBox Futuristi Instruction Manual

Having Fun with Social Coding. Sean Handley. February 25, 2010

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Part III Appendices 165

ERICH PRIMEHAMMER REFACTORING

Introduction to Ruby on Rails

Version Control System - Git. zswu

Getting Things GNOME! Documentation

SECTION 2: Loop Reasoning & HW3 Setup

Burning CDs in Windows XP

(Refer Slide Time: 01.26)

Exercise 2: Automata Theory

SECTION 2: Loop Reasoning & HW3 Setup

Creating a Patch. Created by Carl Heymann on 2010 Sep 14 1

Puppet - Bug #11339 Class ordering bug?

Version Control. Version Control

ChiliProject - Bug # 529: builder is not part of the bundle. Add it to Gemfile

Introduction to Ruby on Rails

Git Introduction CS 400. February 11, 2018

Introduction to Ruby on Rails

Submitting your Work using GIT

Pragmatic Guide to Git

Github/Git Primer. Tyler Hague

I m an egotistical bastard, and I name all my projects after myself. First Linux, now git. Linus Torvalds, creator of Linux and Git

1/20/13 Git tutorial. Git tutorial. Mike Nolta. file:///users/nolta/github/reveal.js/git.html?print-paper#/ 1/31

CSC 2700: Scientific Computing

Office 2016 Excel Basics 09 Video/Class Project #21 Excel Basics 9: Number Formatting and the ROUND Function

Learn Ruby On Rails For Web Development Learn Rails The Fast And Easy Way

Outline The three W s Overview of gits structure Using git Final stuff. Git. A fast distributed revision control system

Integrated Math, Part C Chapter 1 SUPPLEMENTARY AND COMPLIMENTARY ANGLES

Lecture 3. Miscellaneous Ruby and Testing 1 / 40

Tools. SWE 432, Fall Design and Implementation of Software for the Web

AVOIDING THE GIT OF DESPAIR

Git Basi, workflow e concetti avanzati (pt2)

Version Control for the 2- Pizza Team: Merge Conflicts (ELLS 9.5) Armando Fox

CS 61A Higher Order Functions and Recursion Fall 2018 Discussion 2: June 26, Higher Order Functions. HOFs in Environment Diagrams

Git. A fast distributed revision control system. Nils Moschüring PhD Student (LMU)

Programming in C++ PART 2

Introduction to Git and Github

Rancher Part 4: Using the Catalog Example with GlusterFS

This tutorial provides a basic understanding of the infrastructure and fundamental concepts of managing an infrastructure using Chef.

Tangent line problems

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

CuteFlow-V4 Documentation

Installing and Using Docker Toolbox for Mac OSX and Windows

b. Developing multiple versions of a software project in parallel

A BASIC UNDERSTANDING OF VERSION CONTROL

The Parts of a Function:

Software Project (Lecture 4): Git & Github

CIS 194: Homework 4. Due Wednesday, February 18, What is a Number?

Git tutorial. Katie Osterried C2SM. October 22, 2015

Git Branching. Chapter What a Branch Is

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Guide - The limitations in screen layout using the Item Placement Tool

Programming language components

Version control CSE 403

Keeping Rails on the Tracks

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

contribution-guide.org Release

FEEG Applied Programming 3 - Version Control and Git II

Lab 1: Space Invaders. The Introduction

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

Git Workbook. Self-Study Guide to Git. Lorna Mitchell. This book is for sale at

CS 61A Higher Order Functions and Recursion Fall 2018 Discussion 2: June 26, 2018 Solutions. 1 Higher Order Functions. HOFs in Environment Diagrams

Project Management. Overview

Transcription:

String Calculator TDD Kata Created by Roy Osherove http://osherove.com/tdd-kata-1 Ruby Solution based on performance by Corey Haines http://katas.softwarecraftsmanship.org/?p=80

Basic Requirements Create a simple string calculator with a method Add(numbers) that takes a string 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

Rules Start with the simplest test case of an empty string and move to one 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

Getting Start from project shell on Github git clone git@github.com:calebphillips/string_calculator.git cd string_calculator gem install bundler bundle install git checkout shell autotest

The Empty String What s a StringCalculator? `const_missing': uninitialized constant Object::StringCalculator (NameError)

The Empty String That s nicer.

The Empty String This is what we are looking for.

The Empty String Remember to solve things as simply as possible

Single numbers Duplication Saw that one coming.

Single numbers Duplication Remember to solve things as simply as possible

Single numbers What if we could say it like this?

Single numbers Duplication removed. Don t get distracted by RSpec syntax.

Single numbers Expected that, but why don t I see the actual value returned?

Single numbers Still red, but the message is much better.

Single numbers Getting smarter.

Two numbers How did it come up with 2?

Two numbers Remember to solve things as simply as possible

Two numbers Two digit number throws a monkey wrench.

Two numbers Getting a little more general. How many times can you say to_i?

Two numbers Still green. Now there are a lot of details here.

Two numbers Still green and add is a little cleaner now

New Requirement Allow the Add method to handle an unknown amount of numbers

Three numbers Red

Three numbers Why is cheating so much fun?

Three numbers Busted.

Three numbers More general. Are there really 3 different cases here?

Three numbers Ah, that s nicer.

Many numbers Passes as-is.

New Requirement Allow the Add method to handle new lines between numbers (instead of commas). the following input is ok: 1\n2,3 (will equal 6) the following input is NOT ok: 1,\n (not need to prove it - just clarifying)

New lines as delimiters Red.

New lines as delimiters Green., is duplicated.

New lines as delimiters Hide that literal away in a descriptively named method

New lines as delimiters Passes as-is.

New Requirement 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

Custom delimiters Bonus Points: Why did it return 1?

Custom delimiters Delimiter Hard coding abstraction comes in handy - we only changed one method.

Custom delimiters Red

Custom delimiters Are the concepts clear here? Replace constant with variable

Custom delimiters No comments needed.

Custom delimiters A little less noise.

Custom delimiters You can memoize the delimiter if you only want to calculate it once.

New Requirement 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

Negative Numbers Red.

Negative Numbers Remember to solve things as simply as possible

Negative Numbers add reads like the requirements

Negative Numbers Red.

Negative Numbers Refactor in the green.

Negative Numbers Extract a method A little memoization

Negative Numbers Back to Red.

Negative Numbers Done.

Checking your answers git diff master Starting fresh git reset --hard HEAD