Skip to content

Commit

Permalink
Sync tests for practice exercise book-store (#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderploegsma authored Oct 25, 2023
1 parent 64b400c commit d750552
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
28 changes: 22 additions & 6 deletions exercises/practice/book-store/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[17146bd5-2e80-4557-ab4c-05632b6b0d01]
description = "Only a single book"
Expand Down Expand Up @@ -33,16 +40,25 @@ description = "Two groups of four is cheaper than groups of five and three"
description = "Group of four plus group of two is cheaper than two groups of three"

[68ea9b78-10ad-420e-a766-836a501d3633]
description = "Two each of first 4 books and 1 copy each of rest"
description = "Two each of first four books and one copy each of rest"

[c0a779d5-a40c-47ae-9828-a340e936b866]
description = "Two copies of each book"

[18fd86fe-08f1-4b68-969b-392b8af20513]
description = "Three copies of first book and 2 each of remaining"
description = "Three copies of first book and two each of remaining"

[0b19a24d-e4cf-4ec8-9db2-8899a41af0da]
description = "Three each of first 2 books and 2 each of remaining books"
description = "Three each of first two books and two each of remaining books"

[bb376344-4fb2-49ab-ab85-e38d8354a58d]
description = "Four groups of four are cheaper than two groups each of five and three"

[5260ddde-2703-4915-b45a-e54dbbac4303]
description = "Check that groups of four are created properly even when there are more groups of three than groups of five"

[b0478278-c551-4747-b0fc-7e0be3158b1f]
description = "One group of one and four is cheaper than one group of two and three"

[cf868453-6484-4ae1-9dfc-f8ee85bbde01]
description = "One group of one and two plus three groups of four is cheaper than one group of each size"
1 change: 0 additions & 1 deletion exercises/practice/book-store/.meta/version

This file was deleted.

66 changes: 45 additions & 21 deletions exercises/practice/book-store/src/test/java/BookStoreTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Arrays;

import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class BookStoreTest {

// This is sufficient accuracy since we're handling currency values, which should be equal
Expand All @@ -26,118 +26,142 @@ public void setUp() {
public void onlyASingleBook() {
List<Integer> books = Collections.singletonList(1);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(8.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(8.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoOfSameBook() {
List<Integer> books = Arrays.asList(2, 2);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(16.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(16.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void emptyBasket() {
List<Integer> books = Collections.emptyList();
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(0.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(0.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoDifferentBooks() {
List<Integer> books = Arrays.asList(1, 2);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(15.20, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(15.20, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void threeDifferentBooks() {
List<Integer> books = Arrays.asList(1, 2, 3);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(21.60, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(21.60, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void fourDifferentBooks() {
List<Integer> books = Arrays.asList(1, 2, 3, 4);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(25.60, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(25.60, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void fiveDifferentBooks() {
List<Integer> books = Arrays.asList(1, 2, 3, 4, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(30.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(30.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(51.20, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(51.20, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoGroupsOfFourIsCheaperThanGroupsOfFiveAndThree() {
List<Integer> books = Arrays.asList(1, 1, 2, 3, 4, 4, 5, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(51.20, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(51.20, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 4);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(40.80, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(40.80, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoEachOfFirst4BooksAnd1CopyEachOfRest() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(55.60, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(55.60, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void twoCopiesOfEachBook() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(60.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(60.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void threeCopiesOfFirstBookAnd2EachOfRemaining() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(68.00, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(68.00, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void threeEachOFirst2BooksAnd2EachOfRemainingBooks() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(75.20, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(75.20, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void fourGroupsOfFourAreCheaperThanTwoGroupsEachOfFiveAndThree() {
List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(102.4, Assertions.offset(EQUALITY_TOLERANCE));
.isCloseTo(102.4, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void groupsOfFourAreCreatedEvenWhenThereAreMoreGroupsOfThreeThanGroupsOfFive() {
List<Integer> books = Arrays.asList(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(145.6, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void oneGroupOfOneAndFourIsCheaperThanOneGroupOfTwoAndThree() {
List<Integer> books = Arrays.asList(1, 1, 2, 3, 4);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(33.6, Assertions.offset(EQUALITY_TOLERANCE));
}

@Ignore("Remove to run test")
@Test
public void oneGroupOfOneAndTwoPlusThreeGroupsOfFourIsCheaperThanOneGroupOfEachSize() {
List<Integer> books = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5);
assertThat(bookStore.calculateBasketCost(books))
.isCloseTo(100.0, Assertions.offset(EQUALITY_TOLERANCE));
}
}

0 comments on commit d750552

Please sign in to comment.