Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: gnorsilva/dojo
base: 6ea940f074
...
head fork: gnorsilva/dojo
compare: 2d826e2c6b
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
51 _default-kata-setup_/pom.xml
@@ -0,0 +1,51 @@
+<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>
+ <groupId>com.gnorsilva</groupId>
+ <artifactId>ReplaceMe</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>$artifactId</name>
+
+ <properties>
+ <junit.version>4.10</junit.version>
+ <mockito.version>1.9.0</mockito.version>
+ <hamcrest.version>1.2.1</hamcrest.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-integration</artifactId>
+ <version>${hamcrest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ <include>**/*Should.java</include>
+ </includes>
+ <forkMode>always</forkMode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
View
13 _default-kata-setup_/src/test/java/com/gnorsilva/SomethingShould.java
@@ -0,0 +1,13 @@
+package com.gnorsilva;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertTrue;
+
+public class SomethingShould {
+
+ @Test
+ public void knowTheTruth() throws Exception {
+ assertTrue(true);
+ }
+}
View
51 potterBooks/pom.xml
@@ -0,0 +1,51 @@
+<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>
+ <groupId>com.gnorsilva</groupId>
+ <artifactId>potter-books</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>$artifactId</name>
+
+ <properties>
+ <junit.version>4.10</junit.version>
+ <mockito.version>1.9.0</mockito.version>
+ <hamcrest.version>1.2.1</hamcrest.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-integration</artifactId>
+ <version>${hamcrest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ <include>**/*Should.java</include>
+ </includes>
+ <forkMode>always</forkMode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
View
31 potterBooks/src/main/java/com/gnorsilva/BookDiscountCalculator.java
@@ -0,0 +1,31 @@
+package com.gnorsilva;
+
+public class BookDiscountCalculator {
+ private final int numberOfDifferentBooks;
+
+ public BookDiscountCalculator(int numberOfDifferentBooks) {
+ this.numberOfDifferentBooks = numberOfDifferentBooks;
+ }
+
+ public double calculateDiscount() {
+ double discount;
+ switch (numberOfDifferentBooks) {
+ default:
+ discount = 0;
+ break;
+ case 2:
+ discount = 0.05;
+ break;
+ case 3:
+ discount = 0.1;
+ break;
+ case 4:
+ discount = 0.2;
+ break;
+ case 5:
+ discount = 0.25;
+ break;
+ }
+ return discount;
+ }
+}
View
11 potterBooks/src/main/java/com/gnorsilva/BookPriceCalculator.java
@@ -0,0 +1,11 @@
+package com.gnorsilva;
+
+public class BookPriceCalculator {
+
+ public double getPriceFor(Order order) {
+ int numberOfBooks = order.getNumberOfBooks();
+ BookDiscountCalculator calculator = new BookDiscountCalculator(numberOfBooks);
+ double price = ( numberOfBooks * 10 ) * ( 1 - calculator.calculateDiscount());
+ return price;
+ }
+}
View
21 potterBooks/src/main/java/com/gnorsilva/Order.java
@@ -0,0 +1,21 @@
+package com.gnorsilva;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class Order {
+
+ private final List<PotterBooks> books;
+
+ public Order(PotterBooks... books) {
+ this.books = Arrays.asList(books);
+ }
+
+ public void addBooks(PotterBooks book, int numberOfBooks) {
+ //TODO should we implement this? or go with the hashmap idea?
+ }
+
+ public int getNumberOfBooks() {
+ return books.size();
+ }
+}
View
6 potterBooks/src/main/java/com/gnorsilva/PotterBooks.java
@@ -0,0 +1,6 @@
+package com.gnorsilva;
+
+public enum PotterBooks {
+ A, B, C, D, E;
+ public static double BOOK_PRICE = 10;
+}
View
45 potterBooks/src/test/java/com/gnorsilva/BookDiscountCalculatorShould.java
@@ -0,0 +1,45 @@
+package com.gnorsilva;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BookDiscountCalculatorShould {
+
+ @Test
+ public void calculate_no_discount_for_one_book() throws Exception {
+ BookDiscountCalculator calculator = new BookDiscountCalculator(1);
+ double discount = calculator.calculateDiscount();
+ assertThat(discount, is(0.0));
+ }
+
+ @Test
+ public void calculate_5_percent_discount_for_two_different_books() throws Exception {
+ BookDiscountCalculator calculator = new BookDiscountCalculator(2);
+ double discount = calculator.calculateDiscount();
+ assertThat(discount, is(0.05));
+ }
+
+ @Test
+ public void calculate_10_percent_discount_for_three_different_books() throws Exception {
+ BookDiscountCalculator calculator = new BookDiscountCalculator(3);
+ double discount = calculator.calculateDiscount();
+ assertThat(discount, is(0.10));
+ }
+
+ @Test
+ public void calculate_20_percent_discount_for_four_different_books() throws Exception {
+ BookDiscountCalculator calculator = new BookDiscountCalculator(4);
+ double discount = calculator.calculateDiscount();
+ assertThat(discount, is(0.20));
+ }
+
+ @Test
+ public void calculate_25_percent_discount_for_five_different_books() throws Exception {
+ BookDiscountCalculator calculator = new BookDiscountCalculator(5);
+ double discount = calculator.calculateDiscount();
+ assertThat(discount, is(0.25));
+ }
+
+}
View
57 potterBooks/src/test/java/com/gnorsilva/BookPriceCalculatorShould.java
@@ -0,0 +1,57 @@
+package com.gnorsilva;
+
+import org.junit.Test;
+
+import static com.gnorsilva.PotterBooks.*;
+import static junit.framework.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BookPriceCalculatorShould {
+
+ private final BookPriceCalculator priceCalculator = new BookPriceCalculator();
+
+ @Test
+ public void calculate_full_price_for_a_single_book() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A));
+ assertThat(price, is(BOOK_PRICE));
+ }
+
+ @Test
+ public void calculate_full_price_for_two_identical_books() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A,A));
+ double expectedPrice = BOOK_PRICE * 2;
+ assertThat(price, is(expectedPrice));
+ }
+
+ @Test
+ public void calculate_a_price_with_5_percent_discount_for_two_different_books() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A,B));
+ double expectedPrice = (BOOK_PRICE * 2) * 0.95;
+ assertThat(price, is(expectedPrice));
+ }
+
+ @Test
+ public void calculate_a_price_with_10_percent_discount_for_three_different_books() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A,B,C));
+ double expectedPrice = (BOOK_PRICE * 3) * 0.90;
+ assertThat(price, is(expectedPrice));
+ }
+
+ @Test
+ public void calculate_a_price_with_20_percent_discount_for_four_different_books() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A,B,C,D));
+ double expectedPrice = (BOOK_PRICE * 4) * 0.80;
+ assertThat(price, is(expectedPrice));
+ }
+
+ @Test
+ public void calculate_a_price_with_25_percent_discount_for_five_different_books() throws Exception {
+ double price = priceCalculator.getPriceFor(new Order(A,B,C,D,E));
+ double expectedPrice = (BOOK_PRICE * 5) * 0.75;
+ assertThat(price, is(expectedPrice));
+ }
+
+
+
+}
View
38 potterBooks/src/test/java/com/gnorsilva/BookSetIdentifierShould.java
@@ -0,0 +1,38 @@
+package com.gnorsilva;
+
+import org.junit.Test;
+
+import static com.gnorsilva.PotterBooks.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BookSetIdentifierShould {
+
+ @Test
+ public void identify_a_single_book_set_as_one_book() throws Exception {
+ BookSetIdentifier identifier = new BookSetIdentifier(new Order(A));
+ int numberOfUniqueBooks = identifier.nextNumberOfUniqueBooks();
+ assertThat(numberOfUniqueBooks, is(1));
+ }
+
+ @Test
+ public void identify_two_identical_books_as_two_sets_of_one_book() throws Exception {
+ BookSetIdentifier identifier = new BookSetIdentifier(new Order(A,A));
+ assertThat(identifier.nextNumberOfUniqueBooks(), is(1));
+ assertThat(identifier.nextNumberOfUniqueBooks(), is(1));
+ }
+
+
+ private class BookSetIdentifier {
+
+ private final Order order;
+
+ public BookSetIdentifier(Order order) {
+ this.order = order;
+ }
+
+ public int nextNumberOfUniqueBooks() {
+ return order.getNumberOfBooks();
+ }
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.