Skip to content

Commit

Permalink
initial commit, initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Dominguez authored and 12meses12katas committed Mar 1, 2011
1 parent 3e7e1d5 commit 412fa7f
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 0 deletions.
7 changes: 7 additions & 0 deletions josmas/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target
*.iml
.classpath
.project
.settings
*.class
*.swp
29 changes: 29 additions & 0 deletions josmas/java/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----------------------
-- 12 meses 12 katas --
-----------------------
Marzo

Warning! --> this kata contains Java!
Or I should say my folder for this kata contains Java. I have created a very simple maven 2 project to build the project.
'mvn install' or 'mvn test' should do the trick (if you have maven 2 installed!).

I intend to push to git 2 versions of the kata (maybe more), my first attempt at it, and another version when I have been practicing it for a while. I hope to be able to compare and see an evolution from it.

-- Running the specs:
Cucumber features and cuke4duke execution is handled in the maven pom. To run features do:
# Bootstrapping the system (only the first time): mvn -Dcucumber.installGems=true integration-test
mvn integration-test // For all tests to run (also needed to compile everything, at least the first time)
mvn cuke4duke:cucumber // To run just cucumber features

Cucumber features are stored in the features folder.
Step definitions are stored in the test folder, stepdefinitions package.

Peligro! --> esta kata contiene Java!
La kata ha sido desarrollada con Java y maven. Para construir el proyecto, usando 'mvn install' o 'mvn test' debería ser suficiente.

Voy a subir dos versiones de la kata, la primera vez que la complete, y otra versión despues de haberla hecho unas cuantas veces.
La intención es poder comparar las dos soluciones y ver si he evolucionado algo durante ese periodo.

Para ejecutar las especificaciones en Cucumber, sigue las instrucciones en Inglés.

Jos - March 2o11
30 changes: 30 additions & 0 deletions josmas/java/features/fizz_buzz.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: fizz buzz
In order to avoid embarrasment in front of my whole class
As a student who is bad with numbers
I want to print out a list of numbers from 1 to 100 with fizzes and buzzes

Scenario: fizzing multiples of 3
Given My turn is on number 99
Then I need to say fizz instead of the number

Scenario: buzzing multiples of 5
Given My turn is on number 55
Then I need to say buzz instead of the number

Scenario: fizzbuzzing multiples of 3 and 5
Given My turn is on number 15
Then I need to say fizzbuzz instead of the number

Scenario: fizzing numbers with a 3 in them
Given My turn is on number 37
Then I need to say fizz instead of the number

Scenario: buzzing numbers with a 58 in them
Given My turn is on number 58
Then I need to say buzz instead of the number

Scenario: buzzing numbers with a 5 in them
Given My turn is on number 51
Then I need to say fizzbuzz instead of the number

#TODO this is shouting for tabular data!!! Look up how to do it.
104 changes: 104 additions & 0 deletions josmas/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>march-fizz-buzz</artifactId>
<groupId>com.josmas.katas.fizzbuzz</groupId>
<version>0.1</version>
<packaging>jar</packaging>

<name>fizzbuzz</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cuke4duke.version>0.4.3</cuke4duke.version>
<!-- Behind a proxy? -->
<!-- see http://wiki.github.com/aslakhellesoy/cuke4duke/installing-gems -->
<!-- and http://github.com/aslakhellesoy/cuke4duke/issues/issue/36 -->
<!-- http.proxy>proxy.port</http.proxy-->
</properties>
<repositories>
<repository>
<id>codehaus</id>
<url>http://repository.codehaus.org</url>
</repository>
<repository>
<id>cukes</id>
<url>http://cukes.info/maven</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>cukes</id>
<url>http://cukes.info/maven</url>
</pluginRepository>
</pluginRepositories>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>cuke4duke</groupId>
<artifactId>cuke4duke-maven-plugin</artifactId>
<version>${cuke4duke.version}</version>
<configuration>
<jvmArgs>
<jvmArg>
-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory
</jvmArg>
</jvmArgs>
<cucumberArgs>
<cucumberArg>${project.basedir}/target/test-classes</cucumberArg>
</cucumberArgs>
<gems>
<gem>install cuke4duke --version ${cuke4duke.version}</gem>
<!-- Behind a proxy? -->
<!--gem>install cuke4duke -/-version ${cuke4duke.version} -/-http-proxy ${http.proxy}</gem-->
</gems>
</configuration>
<executions>
<execution>
<id>run-features</id>
<phase>integration-test</phase>
<goals>
<goal>cucumber</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2 </version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cuke4duke</groupId>
<artifactId>cuke4duke</artifactId>
<version>${cuke4duke.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.8.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
38 changes: 38 additions & 0 deletions josmas/java/src/main/java/com/jos/katas/fizzbuzz/FizzBuzz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.jos.katas.fizzbuzz;

public class FizzBuzz {

public String say(int number) {
validateInput(number);

StringBuilder result = new StringBuilder();

if (isFizz(number))
result.append("fizz");

if (isBuzz(number))
result.append("buzz");

if (result.toString().isEmpty())
result.append(number);

return result.toString();
}

private void validateInput(int number) {
if (number < 0 || number >100)
throw new IllegalArgumentException("Valid numbers are 1 to 100");
}

private boolean isFizz(int number){
boolean isFizz = false;
isFizz = ( ((number % 3) == 0) || ((number+"").contains("3")) );
return isFizz;
}

private boolean isBuzz(int number){
boolean isBuzz = false;
isBuzz = ( (number % 5) == 0 || (number+"").contains("5") );
return isBuzz;
}
}
65 changes: 65 additions & 0 deletions josmas/java/src/test/java/com/jos/katas/fizzbuzz/FizzBuzzTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.jos.katas.fizzbuzz;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Before;
import org.junit.Test;


public class FizzBuzzTest {

private FizzBuzz fb;

@Before
public void setUp() throws Exception {
fb = new FizzBuzz();
}

@Test
public void itShouldSayFizz(){

assertEquals("1", fb.say(1));
assertEquals("2", fb.say(2));
assertEquals("fizz", fb.say(3));
assertEquals("fizz", fb.say(9));
assertEquals("fizz", fb.say(13));
assertThat("fizz", not(equalTo(fb.say(20))));
assertEquals("fizz", fb.say(21));
assertEquals("fizz", fb.say(99));
}

@Test
public void itShouldSayBuzz(){
assertEquals("buzz", fb.say(5));
assertEquals("buzz", fb.say(20));
assertEquals("buzz", fb.say(25));
assertThat("buzz", not(equalTo(fb.say(21))));
assertEquals("buzz", fb.say(55));
assertEquals("buzz", fb.say(58));
assertEquals("buzz", fb.say(95));
}

@Test
public void itShouldSayFizzBuzz(){
assertEquals("fizzbuzz", fb.say(15));
}

@Test
public void itShouldReturnAInvalidArgumentException(){
try {
fb.say(-1);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException iae){
//ignore
}

try {
fb.say(101);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException iae){
//ignore
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.jos.katas.fizzbuzz.stepdefinitions;

import com.jos.katas.fizzbuzz.FizzBuzz;
import static org.junit.Assert.*;
import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;

public class fizzBuzzStepDefinitions {
private FizzBuzz fb;
private int number;

@Given("^My turn is on number 99$")
public void myTurnIsOnNumber99() {
fb = new FizzBuzz();
this.number = 99;
}

@Then("^I need to say fizz instead of the number$")
public void iNeedToSayFizzInsteadOfTheNumber() {
assertEquals("fizz", fb.say(this.number));
}

@Given("^My turn is on number 55$")
public void myTurnIsOnNumber55() {
fb = new FizzBuzz(); //TODO refactor: how to before?
this.number = 55;
}

@Then("^I need to say buzz instead of the number$")
public void iNeedToSayBuzzInsteadOfTheNumber() {
assertEquals("buzz", fb.say(this.number));
}

@Given("^My turn is on number 15$")
public void myTurnIsOnNumber15() {
fb = new FizzBuzz(); //TODO refactor: how to before?
this.number = 15;
}

@Then("^I need to say fizzbuzz instead of the number$")
public void iNeedToSayFizzbuzzInsteadOfTheNumber() {
assertEquals("fizzbuzz", fb.say(this.number));
}

@Given("^My turn is on number 37$")
public void myTurnIsOnNumber37() {
fb = new FizzBuzz(); //TODO refactor: how to before?
this.number = 37;
}

@Given("^My turn is on number 58$")
public void myTurnIsOnNumber58() {
fb = new FizzBuzz(); //TODO refactor: how to before?
this.number = 58;
}

@Given("^My turn is on number 51$")
public void myTurnIsOnNumber51() {
fb = new FizzBuzz(); //TODO refactor: how to before?
this.number = 51;
}

}

0 comments on commit 412fa7f

Please sign in to comment.