Skip to content

Commit

Permalink
Change Expense to a data class
Browse files Browse the repository at this point in the history
  • Loading branch information
VighneshPath committed Feb 10, 2023
1 parent 1103f9a commit 19902e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.nelkinda.training.model.Expense
import com.nelkinda.training.model.ExpenseType
import java.util.Date

class ExpenseReport {
class ExpenseReport{
fun printReport(expenses: List<Expense>) {
var total = 0
var mealExpenses = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nelkinda.training.model

class Expense {
lateinit var type: ExpenseType
var amount: Int = 0
}
data class Expense(
val type: ExpenseType,
val amount: Int = 0
)

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ class ExpenseReportTest {

@Test
fun printReport() {
val expense1 = Expense()
expense1.amount = 1000
expense1.type = BREAKFAST
val expense1 = Expense(BREAKFAST, 1000)

val expense2 = Expense()
expense2.amount = 2000
expense2.type = DINNER
val expense2 = Expense(DINNER, 2000)

val expectedResult = listOf(
"Expenses ${Date()}", "Breakfast\t1000\t ", "Dinner\t2000\t ",
Expand Down

0 comments on commit 19902e6

Please sign in to comment.