-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatalogue.cfg
184 lines (152 loc) · 4.26 KB
/
Catalogue.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
catalogue {
project "Example Roman Numerals" {
instruction "Write a function to convert from normal numbers to Roman Numerals: e.g.";
instruction " 1 => I // 10 => X // 7 => VII";
test template "RomanNumbersTest1" {
// Beispiel aus : http://exercism.io/exercises/java/roman-numerals/readme
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
@RunWith(Parameterized.class)
public class RomanNumeralsTest {
private int input;
private String expectedOutput;
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{0, ""},
{1, "I"},
{2, "II"},
{3, "III"},
{4, "IV"},
{5, "V"},
{6, "VI"},
{9, "IX"},
{27, "XXVII"},
{48, "XLVIII"},
{59, "LIX"},
{93, "XCIII"},
{141, "CXLI"},
{163, "CLXIII"},
{402, "CDII"},
{575, "DLXXV"},
{911, "CMXI"},
{1024, "MXXIV"},
{3000, "MMM"}
});
}
public RomanNumeralsTest(int input, String expectedOutput) {
this.input = input;
this.expectedOutput = expectedOutput;
}
@Test
public void convertArabicNumberalToRomanNumeral() {
RomanNumeral romanNumeral = new RomanNumeral(input);
assertEquals(expectedOutput, romanNumeral.getRomanNumeral());
}
}
}
test template "RomanNumbersTest2" {
import static org.junit.Assert.*;
import org.junit.Test;
public class RomanNumbersTest2 {
@Test
public void testSomething() {
}
}
}
implementation template "SomeClass1" {
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class RomanNumeral {
private final int number;
private static final Map<Integer, String> CACHE = new HashMap<>();
private static final NavigableMap<Integer, String> NUMBER_TO_ROMAN = initMap();
public RomanNumeral(int number) {
if (number < 0 || number > 3000) {
throw new IllegalArgumentException("Number out of range.");
}
this.number = number;
}
public String getRomanNumeral() {
if (number == 0) {
return "";
}
String result = CACHE.get(number);
if (result != null) {
return result;
}
result = toRomen(number);
CACHE.put(number, result);
return result;
//return number == 0 ? "" : toRomen(number);
}
private static String toRomen(int num) {
int floorNum = NUMBER_TO_ROMAN.floorKey(num);
// Base case
if (floorNum == num) {
return NUMBER_TO_ROMAN.get(num);
}
return NUMBER_TO_ROMAN.get(floorNum) + toRomen(num - floorNum);
}
private static NavigableMap<Integer, String> initMap() {
NavigableMap<Integer, String> map = new TreeMap<>();
map.put(1, "I");
map.put(4, "IV");
map.put(5, "V");
map.put(9, "IX");
map.put(10, "X");
map.put(40, "XL");
map.put(50, "L");
map.put(90, "XC");
map.put(100, "C");
map.put(400, "CD");
map.put(500, "D");
map.put(900, "CM");
map.put(1000, "M");
return map;
}
}
}
implementation template "SomeClass2" {
public class SomeClass2 {
}
}
}
project "Example Project2" {
instruction "Blub";
instruction "Bla";
test template "RomanNumbersTest3" {
import static org.junit.Assert.*;
import org.junit.Test;
public class RomanNumbersTest3 {
@Test
public void testSomething() {
}
}
}
test template "RomanNumbersTest4" {
import static org.junit.Assert.*;
import org.junit.Test;
public class RomanNumbersTest4 {
@Test
public void testSomething() {
}
}
}
implementation template "SomeClass3" {
public class SomeClass1 {
}
}
implementation template "SomeClass4" {
public class SomeClass2 {
}
}
}
}