Skip to content

Instantly share code, notes, and snippets.

@DaveLiddament
Last active January 16, 2019 14:10
Show Gist options
  • Save DaveLiddament/2b23453583681e2eb5f025d0cd33ef27 to your computer and use it in GitHub Desktop.
Save DaveLiddament/2b23453583681e2eb5f025d0cd33ef27 to your computer and use it in GitHub Desktop.
TFF katas

TDD katas

Roman numerals

Write a function that converts an integer into a roman numeral.

Extended exercises:

  • Throw an exception if input is invalid (e.g. 0 or negative)

String calculator

Create a String calculator class with a function: add(string $string) : int

This method takes a string of numbers (each number is separated by a comma. It returns the sum of all the numbers. Empty string is treated as a 0.

For example:

  • "" returns 0
  • "2" returns 2
  • "4,9" returns 13
  • "1,2,3" returns 6

Extended exercises:

  • Don't forget to code for invalid input data.
  • Update add function to take delimiter: add(string $string, string $delimiter) : int
  • Ignore negative numbers. E.g. "4,-9,6" returns 10

Password validator

Write a password strength validator. There is a method: isValid(string $password) : bool

The method returns true if the password is valid. A password is valid if:

  • at least 5 characters long
  • contains 1 lower case letter
  • contains 1 upper case letter
  • contains 1 digit

Template parser

Write an implementation for a template parser: parseTemplate(string $template, array $substitutions) : string

A template might look like this "Hello {name}. Today is turn {age}. Happy Birthday!"

The substitutions array might look like this: ['name' => 'Bob', 'age' => 21]

Extended exercises:

  • Throw exception if the is no value for the place holder.
  • Allow default values. e.g. {age|21}, when no age is present the text after the | is used, in this case 21.
  • Allow the substitution values to contain curly braces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment