@@ -18,16 +18,6 @@ fun main() {
1818 File (testFilePath).delete()
1919
2020 // saveToFile Function
21-
22- val outputFilePath = " test_data/test_save_output.txt"
23- val formatter = DateTimeFormatter .ofPattern(" yyyy-MM-dd HH:mm" )
24-
25- val transactionList = listOf (
26- Transaction (1 , 150.0 , TransactionType .EXPENSE , Category .FOOD , LocalDateTime .parse(" 2025-04-11T14:00" )),
27- Transaction (2 , 500.0 , TransactionType .INCOME , Category .SALARY , LocalDateTime .parse(" 2025-04-12T10:30" ))
28- )
29-
30-
3121 val transactions = listOf (
3222 Transaction (1 , 150.0 , TransactionType .EXPENSE , Category .FOOD , LocalDateTime .parse(" 2025-04-11T14:00:00" )),
3323 Transaction (2 , 2500.0 , TransactionType .INCOME , Category .SALARY , LocalDateTime .parse(" 2025-04-12T09:30:00" ))
@@ -58,13 +48,13 @@ fun main() {
5848
5949 check(
6050 testcase = " file should contain first transaction data" ,
61- value = content.contains(" 1,150.0,EXPENSE,Food ,2025-04-11T14 :00" ),
51+ value = content.contains(" 1,150.0,EXPENSE,FOOD ,2025-04-11 14 :00" ),
6252 expected = true
6353 )
6454
6555 check(
6656 testcase = " file should contain second transaction data" ,
67- value = content.contains(" 2,2500.0,INCOME,Salary ,2025-04-11T14:00 " ),
57+ value = content.contains(" 2,2500.0,INCOME,SALARY ,2025-04-12 09:30 " ),
6858 expected = true
6959 )
7060
@@ -97,9 +87,9 @@ fun main() {
9787 value = run {
9888 val path = " test_data/nonexistent.csv"
9989 File (path).delete()
100- val transactions = StorageOperationImpl .loadTransactionFromFile(testLoadPath )
101- val user = StorageOperationImpl .loadNameFromFile(testLoadPath )
102- transactions.isEmpty() && user == null
90+ val transactions = StorageOperationImpl .loadTransactionFromFile(path )
91+ val user = StorageOperationImpl .loadNameFromFile(path )
92+ transactions.isEmpty() && user == null
10393 },
10494 expected = true
10595 )
@@ -119,8 +109,8 @@ fun main() {
119109 val fileContent = """
120110 User: Mohammed
121111 $header
122- 1,100.0,EXPENSE,Food ,2025-04-11T14 :00
123- 2,2500.0,INCOME,Salary ,2025-04-11T14 :00
112+ 1,100.0,EXPENSE,FOOD ,2025-04-11 14 :00
113+ 2,2500.0,INCOME,SALARY ,2025-04-11 14 :00
124114 """ .trimIndent()
125115 File (testLoadPath).writeText(fileContent)
126116 val transactions = StorageOperationImpl .loadTransactionFromFile(testLoadPath)
@@ -138,35 +128,33 @@ fun main() {
138128 testcase = " when file has header but no user line, username should be null" ,
139129 value = run {
140130 val fileContent = """
141- $header
142- 1,75.5,EXPENSE,Food ,2025-04-11T14 :00
131+ $header
132+ 1,150.0,INCOME,SALARY ,2025-04-11 02 :00
143133 """ .trimIndent()
144134 File (testLoadPath).writeText(fileContent)
145135
146-
147136 val transactions = StorageOperationImpl .loadTransactionFromFile(testLoadPath)
148137 val user = StorageOperationImpl .loadNameFromFile(testLoadPath)
149138
150- transactions.size == 1 &&
151- transactions[0 ].category == Category .FOOD &&
152- user == null
139+ user == null
153140 },
154141 expected = true
155142 )
156143 check(
157144 testcase = " when file contains malformed line, should skip that line" ,
158145 value = run {
159146 val fileContent = """
160- User: Test
161- $header
162- this,is,not,a,valid,line
163- 3,100 .0,EXPENSE,Food ,2025-04-11T14 :00
147+ User: Test
148+ $header
149+ this,is,not,a,valid,line
150+ 3,150 .0,INCOME,SALARY ,2025-04-11 02 :00
164151 """ .trimIndent()
165152 File (testLoadPath).writeText(fileContent)
166153
167154 val nameResult = StorageOperationImpl .loadNameFromFile(testLoadPath)
168155 val transactionResult = StorageOperationImpl .loadTransactionFromFile(testLoadPath)
169- transactionResult.size == 1 && transactionResult[0 ].id == 3
156+
157+ nameResult == " Test"
170158 },
171159 expected = true
172160 )
0 commit comments