Git Product home page Git Product logo

kawauso's Introduction

Kawauso

Kawauso is a test-driven application that demonstrates using FireOtter for spreadsheet-based test specification.

Tests in Kawauso are derived from human-readable specifications living in a spreadsheet under src/test/resources/arithmetic.csv. Application features are built in response to new (failing) tests added as specifications to the spreadsheet.

Example

Consider the introduction of a new feature to Kawauso, with which users can carry a base integer to an arbitrary integer power.

The first step in creating this feature is to determine the success criteria. Let's start simple:

  • Feature: Exponentiation
  • Function name: pow
  • Sample input: 42, 2
  • Expected output: 1764

Now we can add a row to the spreadsheet:

testfunctioninput 1input 2expected output
Exponentiationpow4221764

This causes the tests to break, because the test code doesn't know what to do with the pow function:

[error] Could not run test com.versal.kawauso.tests.ArithmeticTest: scala.MatchError: pow (of class java.lang.String)

Let's fix this in tests.scala:

val output = spec(1) match {
  case "add"      => Arithmetic.add(input1, input2)
  case "subtract" => Arithmetic.subtract(input1, input2)
  case "multiply" => Arithmetic.multiply(input1, input2)
  case "divide"   => Arithmetic.divide(input1, input2)
  case "pow"      => Arithmetic.pow(input1, input2)
}

The test now fails because there is no Arithmetic#pow function:

[error] src/test/scala/tests.scala:20: value pow is not a member of object com.versal.kawauso.Arithmetic
[error]       case "pow"      => Arithmetic.pow(input1, input2)

Let's implement Arithmetic#pow in kawauso.scala:

object Arithmetic {
  def add(x: Int, y: Int): Int = x + y
  def subtract(x: Int, y: Int): Int = x - y
  def multiply(x: Int, y: Int): Int = x * y
  def divide(x: Int, y: Int): Int = x / y
  def pow(x: Int, y: Int): Int = math.pow(x,y).toInt
}

The new test now passes:

[info] ArithmeticTest:
[info] - Addition
[info] - Subtraction
[info] - Multiplication
[info] - Division
[info] - Exponentiation
[info] Passed: : Total 5, Failed 0, Errors 0, Passed 5, Skipped 0

kawauso's People

Contributors

earldouglas avatar

Watchers

James Cloos avatar Victor Konopelko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.