The Lift Kata

Credits

Inspired by Matt Florence

The Lift Kata

Since lifts are everywhere and they contain software, how easy would it be to write a basic one? Let’s TDD a lift, starting with simple behaviors and working toward complex ones. Assume good input from calling code and concentrate on the main flow.

Here are some suggested lift features:

  • a lift responds to calls containing a source floor and direction
  • a lift has an attribute floor, which describes it’s current location
  • a lift delivers passengers to requested floors
  • you may implement current floor monitor
  • you may implement direction arrows
  • you may implement doors (opening and closing)
  • you may implement DING!
  • there can be more than one lift

Starting Points

C++, C#, Clojure, D, Elixir, F#, Go, Haskell, Java, JavaScript, Kotlin, PHP, Python, ReScript, Ruby, Rust, Scala, TypeScript

Clojure, CoffeeScript, C++, C#, Erlang, Groovy, Intercal, Java, JavaScript, Lisp, PHP, Ruby, Scala

Advanced Requirements

  • a lift does not respond immediately. consider options to simulate time, possibly a tick method.
  • lift calls are queued, and executed only as the lift passes a floor

Objects Only

Can you write a lift that does not need to be queried? Try writing a lift that only sends messages to other objects.

Image Credits

Image by Cat Robinson. It shows an opening or closing lift door.