Skip to content

Commit

Permalink
Fix Utilities.getAnswer()
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 10, 2024
1 parent a86573b commit f55dcf6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rust/target
**/dist/*
docs/_static/test-js.html
javascript/src/lib/fallbacks
java/target
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Olivia's Project Euler Solutions
| | | | |CodeQL| |br| |
| | | | |C#-lint| |
+------------+--------------------------+--------+-------------------+
| Java | Java 8+ | 6 | |Javai| |br| |
| Java | Java 8+ | 7 | |Javai| |br| |
| | | | |Ja-Cov| |br| |
| | | | |CodeQL| |br| |
| | | | |Java-lint| |
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`21` | | | | | |:py-d:`0021`| |
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`22` |:c-d:`0022` |:cp-d:`0022`|:cs-d:`0022`|:ja-i:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`|
|:prob:`22` |:c-d:`0022` |:cp-d:`0022`|:cs-d:`0022`|:ja-d:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`23` | | | | | |:py-d:`0023`| |
+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
21 changes: 5 additions & 16 deletions java/src/main/java/euler/lib/Utilities.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
package euler;
package euler.lib;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Utilities {

private static Path getDataPath(String name) throws IOException {
String absolutePath;
try {
ClassLoader classLoader = Utilities.class.getClassLoader();
File file = new File(classLoader.getResource("Utilities.class").toURI());
absolutePath = file.getAbsolutePath();
} catch (URISyntaxException e) {
e.printStackTrace();
throw new IOException();
}
if (absolutePath == null) {
throw new IOException("Unable to determine file path.");
}
Path filePath = Paths.get(absolutePath).getParent().resolve("../../../../../_data").resolve(name);
Path classPath = Paths.get(Utilities.class.getProtectionDomain().getCodeSource().getLocation().getPath());
Path classDir = classPath.getParent();
Path filePath = classDir.getParent().getParent().resolve("_data").resolve(name);
return filePath.toAbsolutePath();
}

Expand All @@ -41,6 +29,7 @@ public static Object getAnswer(long n) throws IOException {
String csvContent = getDataFileText("answers.csv");
try (BufferedReader reader = new BufferedReader(new StringReader(csvContent))) {
String line;
reader.readLine();
while ((line = reader.readLine()) != null) {
String[] arr = line.split("\t");
if (arr.length < 4) continue;
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/euler/p0022.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.util.Arrays;

import euler.Utilities;
import euler.lib.Utilities;

public class p0022 implements IEuler {
@Override
Expand Down
19 changes: 10 additions & 9 deletions java/src/test/java/EulerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package euler;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.api.Assertions;
Expand All @@ -8,30 +6,33 @@
import java.lang.reflect.Method;
import java.util.stream.Stream;

import euler.*;
import euler.lib.Utilities;

public class EulerTest {
private static final long ONE_MINUTE_NS = 60_000_000_000L; // 1 minute in nanoseconds

// Data provider for parameterized tests
static Stream<Object[]> data() throws IOException {
return Stream.of(
new Object[]{p0000.class, false, 0},
new Object[]{p0001.class, false, 233168},
new Object[]{p0002.class, false, 4613732},
new Object[]{p0004.class, false, 906609},
new Object[]{p0006.class, false, 25164150},
new Object[]{p0001.class, false, Utilities.getAnswer(1)},
new Object[]{p0002.class, false, Utilities.getAnswer(2)},
new Object[]{p0004.class, false, Utilities.getAnswer(4)},
new Object[]{p0006.class, false, Utilities.getAnswer(6)},
// new Object[]{p0008.class, false, Utilities.getAnswer(8)},
new Object[]{p0009.class, false, 31875000},
new Object[]{p0009.class, false, Utilities.getAnswer(9)},
// new Object[]{p0011.class, false, Utilities.getAnswer(11)},
// new Object[]{p0013.class, false, Utilities.getAnswer(13)},
// new Object[]{p0014.class, false, Utilities.getAnswer(14)},
// new Object[]{p0015.class, false, Utilities.getAnswer(15)},
// new Object[]{p0016.class, false, Utilities.getAnswer(16)},
// new Object[]{p0017.class, false, Utilities.getAnswer(17)},
// new Object[]{p0020.class, false, Utilities.getAnswer(20)},
// new Object[]{p0022.class, false, 871198282},
new Object[]{p0022.class, false, Utilities.getAnswer(22)},
// new Object[]{p0034.class, false, Utilities.getAnswer(34)},
// new Object[]{p0076.class, true, Utilities.getAnswer(76)},
new Object[]{p0836.class, false, "aprilfoolsjoke"}
new Object[]{p0836.class, false, Utilities.getAnswer(836)}
);
}

Expand Down

0 comments on commit f55dcf6

Please sign in to comment.