Skip to content

paddycakes/fizzbuzz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FizzBuzz

Overview

An application to generate FizzBuzz output based on:

  • a configurable 'from' and 'to' range
  • whether to include the LUCK override rule
  • whether to include statistics

I have used Java 8 to implement this and attempted a functional approach where appropriate.

Tests are written in Scala and Groovy as well as Java.

The specification can be found in /docs/Specification.docx

Gradle Build

The project is built with Gradle:

http://www.gradle.org/

This project includes the Gradle Wrapper (gradlew):

http://www.gradle.org/docs/current/userguide/gradle_wrapper.html

The Gradle Wrapper is a batch script on Windows or a shell script on *nix. When you start a Gradle build via the wrapper, Gradle will be automatically downloaded and used to run the build. This provides the benefit that anyone can work with it without needing to install Gradle beforehand. It also ensures that users are guaranteed to use the version of Gradle that the build was designed to work with.

Spock and Scala for BDD Testing

I have provided a JUnit test suite in the following class which can be found in src/test/java:

com.agilesphere.FizzBuzzTests

However, I have also written some tests with a BDD approach using Spock:

http://spockframework.org

Spock is a developer testing and specification framework for Java and Groovy applications. It provides a very powerful and expressive specification language through the power of a Groovy DSL. Spock specifications conventionally have the suffix 'Spec'. One of it's power features, and one which I have used, is the ability it affords for data driven testing. Often it is useful to exercise the same test code multiple times, with varying inputs and expected results. Spock’s data driven testing support makes this extremely easy.

I have utilised this in the following specification tests which can be found in src/test/groovy:

com.agilesphere.FizzBuzzSpec
com.agilesphere.rules.RulesSpec
com.agilesphere.utils.DigitSpliteratorSpec

As well as Spock, I have also used ScalaTest:

http://www.scalatest.org

with the WordSpec trait to provide a nice hierarchical/nested structure to group related tests as well as providing very readable specifications.

An example of this type of test can be found in src/test/scala:

com.agilesphere.FizzBuzzScalaSpec

Build Tasks

Clean the output directories:

./gradlew clean

Running tests

./gradlew test

Test reports can be found at:

build/reports/tests/index.html

Running application

Firstly, install the application

./gradlew installApp

Then navigate to

build/install/fizzbuzz

and execute on Unix

./bin/fizzbuzz

or on Windows

./bin/fizzbuzz.bat

The program will ask the following questions before generating the FizzBuzz output:

  1. What number to generate FizzBuzz from?
  2. What number to generate FizzBuzz to?
  3. Whether to include the LUCK override rule?
  4. Whether to include FizzBuzz statistics in output?

Creating a distribution

Execute this command

./gradlew distZip

and then you will find the distribution created at:

build/distributions/fizzbuzz.zip

About

FizzBuzz implementation in Java 8

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors