Skip to content

Commit 0ef4420

Browse files
authored
Sync tests for practice exercise ledger (#2627)
* Sync tests from exercise ledger, update reference resolution and class visualized to students, cause this is a reformat exercise * Test pipeline with split using dot instead of comma
1 parent bf6aa10 commit 0ef4420

File tree

4 files changed

+150
-102
lines changed

4 files changed

+150
-102
lines changed

exercises/practice/ledger/.meta/src/reference/java/Ledger.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.List;
55

66
public class Ledger {
7-
public LedgerEntry createLedgerEntry(String d, String desc, double c) {
7+
public LedgerEntry createLedgerEntry(String d, String desc, int c) {
88
LedgerEntry le = new LedgerEntry();
99
le.setChange(c);
1010
le.setDescription(desc);
@@ -89,9 +89,9 @@ public String format(String cur, String loc, LedgerEntry[] entries) {
8989

9090
String converted = null;
9191
if (e.getChange() < 0) {
92-
converted = String.format("%.02f", e.getChange() * -1);
92+
converted = String.format("%.02f", (e.getChange() / 100) * -1);
9393
} else {
94-
converted = String.format("%.02f", e.getChange());
94+
converted = String.format("%.02f", e.getChange() / 100);
9595
}
9696

9797
String[] parts = converted.split("\\.");
@@ -106,10 +106,21 @@ public String format(String cur, String loc, LedgerEntry[] entries) {
106106
count++;
107107
}
108108

109-
amount = curSymb + amount + decSep + parts[1];
109+
if (loc.equals("nl-NL")) {
110+
amount = curSymb + " " + amount + decSep + parts[1];
111+
} else {
112+
amount = curSymb + amount + decSep + parts[1];
113+
}
114+
110115

111-
if (e.getChange() < 0) {
112-
amount = "-" + amount;
116+
if (e.getChange() < 0 && loc.equals("en-US")) {
117+
amount = "(" + amount + ")";
118+
} else if (e.getChange() < 0 && loc.equals("nl-NL")) {
119+
amount = curSymb + " -" + amount.replace(curSymb, "").trim() + " ";
120+
} else if (loc.equals("nl-NL")) {
121+
amount = " " + amount + " ";
122+
} else {
123+
amount = amount + " ";
113124
}
114125

115126
s = s + "\n";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[d131ecae-a30e-436c-b8f3-858039a27234]
13+
description = "empty ledger"
14+
15+
[ce4618d2-9379-4eca-b207-9df1c4ec8aaa]
16+
description = "one entry"
17+
18+
[8d02e9cb-e6ee-4b77-9ce4-e5aec8eb5ccb]
19+
description = "credit and debit"
20+
21+
[502c4106-0371-4e7c-a7d8-9ce33f16ccb1]
22+
description = "multiple entries on same date ordered by description"
23+
include = false
24+
25+
[29dd3659-6c2d-4380-94a8-6d96086e28e1]
26+
description = "final order tie breaker is change"
27+
28+
[9b9712a6-f779-4f5c-a759-af65615fcbb9]
29+
description = "overlong description is truncated"
30+
31+
[67318aad-af53-4f3d-aa19-1293b4d4c924]
32+
description = "euros"
33+
34+
[bdc499b6-51f5-4117-95f2-43cb6737208e]
35+
description = "Dutch locale"
36+
37+
[86591cd4-1379-4208-ae54-0ee2652b4670]
38+
description = "Dutch locale and euros"
39+
40+
[876bcec8-d7d7-4ba4-82bd-b836ac87c5d2]
41+
description = "Dutch negative number with 3 digits before decimal point"
42+
43+
[29670d1c-56be-492a-9c5e-427e4b766309]
44+
description = "American negative number with 3 digits before decimal point"
45+
46+
[9c70709f-cbbd-4b3b-b367-81d7c6101de4]
47+
description = "multiple entries on same date ordered by description"
48+
reimplements = "502c4106-0371-4e7c-a7d8-9ce33f16ccb1"

exercises/practice/ledger/src/main/java/Ledger.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.List;
55

66
public class Ledger {
7-
public LedgerEntry createLedgerEntry(String d, String desc, double c) {
7+
public LedgerEntry createLedgerEntry(String d, String desc, int c) {
88
LedgerEntry le = new LedgerEntry();
99
le.setChange(c);
1010
le.setDescription(desc);
@@ -89,9 +89,9 @@ public String format(String cur, String loc, LedgerEntry[] entries) {
8989

9090
String converted = null;
9191
if (e.getChange() < 0) {
92-
converted = String.format("%.02f", e.getChange() * -1);
92+
converted = String.format("%.02f", (e.getChange() / 100) * -1);
9393
} else {
94-
converted = String.format("%.02f", e.getChange());
94+
converted = String.format("%.02f", e.getChange() / 100);
9595
}
9696

9797
String[] parts = converted.split("\\.");
@@ -106,12 +106,23 @@ public String format(String cur, String loc, LedgerEntry[] entries) {
106106
count++;
107107
}
108108

109-
amount = curSymb + amount + decSep + parts[1];
110-
111-
if (e.getChange() < 0) {
112-
amount = "-" + amount;
109+
if (loc.equals("nl-NL")) {
110+
amount = curSymb + " " + amount + decSep + parts[1];
111+
} else {
112+
amount = curSymb + amount + decSep + parts[1];
113113
}
114+
114115

116+
if (e.getChange() < 0 && loc.equals("en-US")) {
117+
amount = "(" + amount + ")";
118+
} else if (e.getChange() < 0 && loc.equals("nl-NL")) {
119+
amount = curSymb + " -" + amount.replace(curSymb, "").trim() + " ";
120+
} else if (loc.equals("nl-NL")) {
121+
amount = " " + amount + " ";
122+
} else {
123+
amount = amount + " ";
124+
}
125+
115126
s = s + "\n";
116127
s = s + String.format("%s | %-25s | %13s",
117128
date,

0 commit comments

Comments
 (0)