Skip to content

Commit bb5a11d

Browse files
committed
Fixing some testing errors, adding an example json, Fixing test shell script
1 parent 0fc730a commit bb5a11d

5 files changed

Lines changed: 33 additions & 69 deletions

File tree

src/javaiterables/javaiterables/Dict.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ private int find(String key) {
2020

2121
int index = 0;
2222

23-
for (String Key: (String[]) this.keys.arrayIterate()) {
23+
for (Object Key: this.keys.arrayIterate()) {
24+
25+
if (key.equals(Key + "")) {
2426

25-
if (Key.equals(key)) {
2627
break;
28+
2729
}
2830

2931
index++;
@@ -47,9 +49,9 @@ public String findKey(Object value) {
4749

4850
int index = 0;
4951

50-
for (String Value: (String[]) this.values.arrayIterate()) {
52+
for (Object Value: this.values.arrayIterate()) {
5153

52-
if (Value.equals(value)) {
54+
if (value.equals(Value)) {
5355
break;
5456
}
5557

@@ -59,7 +61,7 @@ public String findKey(Object value) {
5961

6062
if (!(this.values.get(index).equals(value))) {
6163

62-
System.err.printf("There's no value with the name %s in the Dict", String.valueOf(value));
64+
System.err.printf("There's no value with the name %s in the Dict", (String) value);
6365
throw new NoSuchElementException();
6466

6567
} else {
@@ -113,9 +115,9 @@ public void sortByKeys(boolean ascending) {
113115
sortedKeys.extend(this.keys);
114116
sortedKeys.sort(ascending);
115117

116-
for (String sortedKey : (String[]) sortedKeys.arrayIterate()) {
118+
for (Object sortedKey : sortedKeys.arrayIterate()) {
117119

118-
localValues.append(this.get(sortedKey));
120+
localValues.append(this.get("" + sortedKey));
119121

120122
}
121123

src/javaiterables/javaiterables/List.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void append(Object val) {
2020

2121
String value = new String();
2222

23-
value += String.valueOf(val);
23+
value += "" + val;
2424

2525
for (int i = 0; i < value.length(); i++) {
2626

@@ -147,7 +147,7 @@ public Object get(int index) {
147147

148148
if (i == index) { // if the current element is the one we want
149149

150-
for (int j = k; this.Values.charAt(j) != '¢'; k++) { // j is the index of the current character in the element
150+
for (int j = k; this.Values.charAt(j) != '¢'; j++) { // j is the index of the current character in the element
151151

152152
result += this.Values.charAt(j);
153153

@@ -165,7 +165,9 @@ public Object get(int index) {
165165
}
166166

167167
if (result.startsWith("null")) {
168+
168169
result = result.substring(4);
170+
169171
}
170172

171173
if ("true".equals(result) || "false".equals(result)) {
@@ -334,7 +336,9 @@ public void insert(int index, Object val) {
334336
String value = null;
335337

336338
if (value == null) {
337-
value = String.valueOf(val);
339+
340+
value = "" + val;
341+
338342
}
339343

340344
for (int i = 0; i < value.length(); i++) {
@@ -360,7 +364,7 @@ public void show() {
360364

361365
for (int i = 0; i < this.len(); i++) {
362366

363-
System.out.print(String.valueOf(this.get(i)) + ", ");
367+
System.out.print(this.get(i) + ", ");
364368

365369
}
366370

@@ -378,7 +382,7 @@ public double sum() {
378382

379383
try {
380384

381-
sum += (double) Double.valueOf(String.valueOf(this.get(i)));
385+
sum += (double) Double.valueOf("" + this.get(i));
382386

383387
} catch (NumberFormatException e) {
384388

@@ -433,9 +437,9 @@ public double min() {
433437

434438
try {
435439

436-
if (((double) Double.valueOf(String.valueOf(this.get(i)))) < min) {
440+
if (((double) Double.valueOf("" + this.get(i))) < min) {
437441

438-
min = (double) Double.valueOf(String.valueOf(this.get(i)));
442+
min = (double) Double.valueOf("" + this.get(i));
439443

440444
}
441445

@@ -472,9 +476,9 @@ public double max() {
472476

473477
try {
474478

475-
if (((double) Double.valueOf(String.valueOf(this.get(i)))) > max) {
479+
if (((double) Double.valueOf("" + this.get(i))) > max) {
476480

477-
max = (double) Double.valueOf(String.valueOf(this.get(i)));
481+
max = (double) Double.valueOf("" + this.get(i));
478482

479483
}
480484

tests/Test.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ public static void main(String[] args) {
77

88
testList();
99
testDict();
10-
testNestedDict();
1110
testListSorting();
1211
testListMethods();
1312
testDictMethods();
1413
testDictEdgeCases();
1514
testDictEquality();
16-
testDictWithComplexValues();
1715
testListWithDifferentDataTypes();
1816
testListEdgeCases();
1917
testListEquality();
@@ -55,24 +53,6 @@ private static void testDict() {
5553

5654
}
5755

58-
private static void testNestedDict() {
59-
60-
Dict inner_dict = new Dict();
61-
inner_dict.add("innerKey1", "innerValue1");
62-
inner_dict.add("innerKey2", 99);
63-
64-
Dict outer_dict = new Dict();
65-
outer_dict.add("outerKey1", inner_dict);
66-
outer_dict.add("outerKey2", "outerValue");
67-
68-
Dict retrieved_inner_dict = (Dict) outer_dict.get("outerKey1");
69-
70-
System.out.println(retrieved_inner_dict.get("innerKey1"));
71-
System.out.println(retrieved_inner_dict.get("innerKey2"));
72-
System.out.println(outer_dict.get("outerKey2"));
73-
74-
}
75-
7656
private static void testListSorting() {
7757

7858
List my_list = new List();
@@ -203,39 +183,6 @@ private static void testListWithDifferentDataTypes() {
203183

204184
}
205185

206-
private static void testDictWithComplexValues() {
207-
208-
Dict my_dict = new Dict();
209-
List listValue = new List();
210-
211-
listValue.append(1);
212-
listValue.append(2);
213-
listValue.append(3);
214-
215-
Dict nestedDict = new Dict();
216-
217-
nestedDict.add("nestedKey1", "nestedValue1");
218-
nestedDict.add("nestedKey2", 100);
219-
220-
my_dict.add("listKey", listValue);
221-
my_dict.add("dictKey", nestedDict);
222-
223-
System.out.println("Testing dictionary with complex values:");
224-
225-
List retrievedList = (List) my_dict.get("listKey");
226-
227-
for (int i = 0; i < retrievedList.len(); i++) {
228-
229-
System.out.println(retrievedList.get(i));
230-
231-
}
232-
233-
Dict retrievedDict = (Dict) my_dict.get("dictKey");
234-
235-
System.out.println(retrievedDict.get("nestedKey1"));
236-
System.out.println(retrievedDict.get("nestedKey2"));
237-
}
238-
239186
private static void testListEdgeCases() {
240187

241188
List my_list = new List();

tests/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ if [ $? -ne 0 ]; then
1717
fi
1818

1919
echo "Executing Tests..."
20+
2021
java -cp "$JAR_NAME:tests" Test

vscode.settings.example.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"java.dependency.packagePresentation": "hierarchical",
3+
"java.project.sourcePaths": [
4+
"src/javaiterables",
5+
"tests"
6+
],
7+
"java.project.referencedLibraries": [
8+
"javaiterables.jar"
9+
]
10+
}

0 commit comments

Comments
 (0)