Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update book-store to match latest canonical json. #498

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/book-store/example.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object BookStore {
private val bookPrice = 8
private val bookPrice = 800
private val discounts =
Map((1, 0.0),
(2, 5.0),
Expand Down
34 changes: 19 additions & 15 deletions exercises/book-store/src/test/scala/BookStoreTest.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import org.scalatest.{Matchers, FunSuite}

/** @version 1.0.1 */
/** @version 1.3.0 */
class BookStoreTest extends FunSuite with Matchers {

test("Only a single book") {
BookStore.total(List(1)) should be (8)
BookStore.total(List(1)) should be (800)
}

test("Two of the same book") {
pending
BookStore.total(List(2, 2)) should be (16)
BookStore.total(List(2, 2)) should be (1600)
}

test("Empty basket") {
Expand All @@ -20,51 +19,56 @@ class BookStoreTest extends FunSuite with Matchers {

test("Two different books") {
pending
BookStore.total(List(1, 2)) should be (15.2)
BookStore.total(List(1, 2)) should be (1520)
}

test("Three different books") {
pending
BookStore.total(List(1, 2, 3)) should be (21.6)
BookStore.total(List(1, 2, 3)) should be (2160)
}

test("Four different books") {
pending
BookStore.total(List(1, 2, 3, 4)) should be (25.6)
BookStore.total(List(1, 2, 3, 4)) should be (2560)
}

test("Five different books") {
pending
BookStore.total(List(1, 2, 3, 4, 5)) should be (30)
BookStore.total(List(1, 2, 3, 4, 5)) should be (3000)
}

test("Two groups of four is cheaper than group of five plus group of three") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 5)) should be (51.2)
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 5)) should be (5120)
}

test("Group of four plus group of two is cheaper than two groups of three") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 4)) should be (40.8)
BookStore.total(List(1, 1, 2, 2, 3, 4)) should be (4080)
}

test("Two each of first 4 books and 1 copy each of rest") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5)) should be (55.6)
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5)) should be (5560)
}

test("Two copies of each book") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5)) should be (60)
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5)) should be (6000)
}

test("Three copies of first book and 2 each of remaining") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1)) should be (68)
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1)) should be (6800)
}

test("Three each of first 2 books and 2 each of remaining books") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2)) should be (75.2)
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2)) should be (7520)
}

test("Four groups of four are cheaper than two groups each of five and three") {
pending
BookStore.total(List(1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5)) should be (10240)
}
}
}
6 changes: 3 additions & 3 deletions testgen/src/main/scala/BookStoreTestGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import java.io.File

import testgen.TestSuiteBuilder
import testgen.TestSuiteBuilder.fromLabeledTest
import testgen.TestSuiteBuilder.fromLabeledTestFromInput

object BookStoreTestGenerator {
def main(args: Array[String]): Unit = {
val file = new File("book-store.json")
val file = new File("src/main/resources/book-store.json")

val code = TestSuiteBuilder.build(file, fromLabeledTest("basket"))
val code = TestSuiteBuilder.build(file, fromLabeledTestFromInput("basket"))
println(s"-------------")
println(code)
println(s"-------------")
Expand Down