Commit 856ad7b7 authored by Javier Hernández's avatar Javier Hernández 🤓

Output3 test and data classes corrections

- Added output3 test
- pharma property corrected for testing acceptation
parent 49f3d4bf
...@@ -6,7 +6,7 @@ import com.lm.sales.model.medicals.Pills ...@@ -6,7 +6,7 @@ import com.lm.sales.model.medicals.Pills
class PillsBuilder { class PillsBuilder {
private lateinit var name: String private lateinit var name: String
private lateinit var pharma: String private var pharma: String? = null
private lateinit var presentation: Presentation private lateinit var presentation: Presentation
private var isImported: Boolean = false private var isImported: Boolean = false
private var basePrice: Double = 0.0 private var basePrice: Double = 0.0
......
...@@ -3,5 +3,5 @@ package com.lm.sales.model.medicals ...@@ -3,5 +3,5 @@ package com.lm.sales.model.medicals
import com.lm.sales.model.Product import com.lm.sales.model.Product
interface Medicals: Product { interface Medicals: Product {
val pharma: String val pharma: String?
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ import com.lm.sales.model.Presentation ...@@ -4,7 +4,7 @@ import com.lm.sales.model.Presentation
import com.lm.sales.model.Taxes import com.lm.sales.model.Taxes
data class Pills(override val name: String, data class Pills(override val name: String,
override val pharma: String, override val pharma: String? = null,
override val imported: Boolean, override val imported: Boolean,
override val basePrice: Double, override val basePrice: Double,
override val presentation: Presentation?, override val presentation: Presentation?,
......
...@@ -41,7 +41,7 @@ class TaxesCalculator { ...@@ -41,7 +41,7 @@ class TaxesCalculator {
// kotlin's round rounds automatically // kotlin's round rounds automatically
return Taxes().apply { return Taxes().apply {
taxesAmount = round(taxes) taxesAmount = round(taxes)
afterTaxesAmount = round(product.basePrice.plus(taxes)) afterTaxesAmount = product.basePrice.plus(taxesAmount)
} }
} }
......
...@@ -18,7 +18,6 @@ class ShoppingTests { ...@@ -18,7 +18,6 @@ class ShoppingTests {
// Builds book from input 1 an calculates taxes // Builds book from input 1 an calculates taxes
val book = BookBuilder().withName("book") val book = BookBuilder().withName("book")
.isImported(false)
.withBasePrice(12.49) .withBasePrice(12.49)
.build().apply { .build().apply {
taxes = TaxesCalculator.calculate(this) taxes = TaxesCalculator.calculate(this)
...@@ -26,7 +25,6 @@ class ShoppingTests { ...@@ -26,7 +25,6 @@ class ShoppingTests {
// Builds CD from input 1 and calculates taxes // Builds CD from input 1 and calculates taxes
val cd = CDBuilder().withName("music CD") val cd = CDBuilder().withName("music CD")
.isImported(false)
.withBasePrice(14.99) .withBasePrice(14.99)
.build().apply { .build().apply {
taxes = TaxesCalculator.calculate(this) taxes = TaxesCalculator.calculate(this)
...@@ -53,7 +51,7 @@ class ShoppingTests { ...@@ -53,7 +51,7 @@ class ShoppingTests {
fun input2(){ fun input2(){
// Builds chocolates box from input2 and calculate taxes // Builds chocolates box from input2 and calculate taxes
val chocoBox = ChocolatesBuilder().withName("chocolates") val importedChocoBox = ChocolatesBuilder().withName("chocolates")
.withPresentation(Presentation.box) .withPresentation(Presentation.box)
.isImported(true) .isImported(true)
.withBasePrice(10.00) .withBasePrice(10.00)
...@@ -62,7 +60,7 @@ class ShoppingTests { ...@@ -62,7 +60,7 @@ class ShoppingTests {
} }
// Builds bottle of perfume from input2 and calculate taxes // Builds bottle of perfume from input2 and calculate taxes
val perfume = PerfumeBuilder().withName("perfume") val importedPerfume = PerfumeBuilder().withName("perfume")
.withPresentation(Presentation.bottle) .withPresentation(Presentation.bottle)
.isImported(true) .isImported(true)
.withBasePrice(47.50) .withBasePrice(47.50)
...@@ -71,13 +69,59 @@ class ShoppingTests { ...@@ -71,13 +69,59 @@ class ShoppingTests {
} }
val cart = Cart().apply { val cart = Cart().apply {
productList.add(chocoBox) productList.add(importedChocoBox)
productList.add(perfume) productList.add(importedPerfume)
} }
// Adds cart products to recipe and prints it // Adds cart products to recipe and prints it
RecipeBuilder().withProducts(cart.productList).withRecipeName("Output 2:").printRecipe() RecipeBuilder().withProducts(cart.productList).withRecipeName("Output 2:").printRecipe()
} }
@Test
fun input3(){
// Builds importeds bottle of perfume from input3 and calculate taxes
val importedPerfume = PerfumeBuilder().withName("perfume")
.withPresentation(Presentation.bottle)
.isImported(true)
.withBasePrice(27.99)
.build().apply {
taxes = TaxesCalculator.calculate(this)
}
// Builds bottle of perfume from input3 and calculate taxes
val perfume = PerfumeBuilder().withName("perfume")
.withPresentation(Presentation.bottle)
.withBasePrice(18.99)
.build().apply {
taxes = TaxesCalculator.calculate(this)
}
// Builds packet of headache pills from input3 and calculate taxes
val pills = PillsBuilder().withName("headache pills")
.withPresentation(Presentation.packet)
.withBasePrice(9.75)
.build().apply {
taxes = TaxesCalculator.calculate(this)
}
// Builds box of imported chocolates from input3 and calculate taxes
val importedChocoBox = ChocolatesBuilder().withName("chocolates")
.withPresentation(Presentation.box)
.isImported(true)
.withBasePrice(11.25)
.build().apply {
taxes = TaxesCalculator.calculate(this)
}
val cart = Cart().apply {
productList.add(importedPerfume)
productList.add(perfume)
productList.add(pills)
productList.add(importedChocoBox)
}
// Adds cart products to recipe and prints it
RecipeBuilder().withProducts(cart.productList).withRecipeName("Output 3:").printRecipe()
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment