Skip to content

Commit 791ce99

Browse files
committed
Merge branch 'develop'
2 parents 466beeb + c39994f commit 791ce99

File tree

6 files changed

+82
-36
lines changed

6 files changed

+82
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Each project is configured in specific environments, as described below:
1414

1515
- C++ project: C++20 / [CMake](https://cmake.org/) build / [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/), [Google Test](https://google.github.io/googletest/), [Google Benchmark](https://github.com/google/benchmark), [fmt](https://github.com/fmtlib/fmt) packages / [vcpkg](https://github.com/microsoft/vcpkg) package manager
1616
- Python project: Python 3.11 / [Poetry](https://python-poetry.org/) / [NumPy](https://numpy.org/), [SciPy](https://www.scipy.org/), [NetworkX](https://networkx.org/), [pytest](https://docs.pytest.org/), [pytest-benchmark](https://pytest-benchmark.readthedocs.io/en/latest/) packages
17-
- Java project: Java 17 / [Gradle](https://gradle.org/) build / [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries
17+
- Java project: Java 21 / [Gradle](https://gradle.org/) build / [Guava](https://github.com/google/guava), [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries
1818

1919
## Table of Contents
2020

README_ko-KR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
- C++ project: C++20 / [CMake](https://cmake.org/) build / [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/), [Google Test](https://google.github.io/googletest/), [Google Benchmark](https://github.com/google/benchmark), [fmt](https://github.com/fmtlib/fmt) packages / [vcpkg](https://github.com/microsoft/vcpkg) package manager
1616
- Python project: Python 3.11 / [Poetry](https://python-poetry.org/) / [NumPy](https://numpy.org/), [SciPy](https://www.scipy.org/), [NetworkX](https://networkx.org/), [pytest](https://docs.pytest.org/), [pytest-benchmark](https://pytest-benchmark.readthedocs.io/en/latest/) packages
17-
- Java project: Java 17 / [Gradle](https://gradle.org/) build / [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries
17+
- Java project: Java 21 / [Gradle](https://gradle.org/) build / [Guava](https://github.com/google/guava), [JUnit](https://junit.org/), [Java Microbenchmark Harness (JMH)](https://github.com/openjdk/jmh) libraries

java-algorithm/build.gradle.kts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ plugins {
55
java
66
}
77

8-
group = "org.example"
9-
version = "1.0-SNAPSHOT"
8+
group = "org.example.algorithm"
9+
version = "1.0"
1010

1111
java {
12-
sourceCompatibility = JavaVersion.VERSION_17
13-
targetCompatibility = JavaVersion.VERSION_17
12+
sourceCompatibility = JavaVersion.VERSION_21
13+
targetCompatibility = JavaVersion.VERSION_21
1414
}
1515

1616
configurations {
@@ -47,26 +47,26 @@ repositories {
4747
}
4848

4949
dependencies {
50-
implementation("com.google.guava:guava:31.1-jre")
50+
implementation("com.google.guava:guava:33.0.0-jre")
5151
implementation("org.javatuples:javatuples:1.2")
52-
implementation("org.slf4j:slf4j-api:2.0.5")
53-
implementation("org.apache.logging.log4j:log4j-api:2.19.0")
54-
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
55-
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.19.0")
56-
compileOnly("org.projectlombok:lombok:1.18.24")
57-
annotationProcessor("org.projectlombok:lombok:1.18.24")
58-
annotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.35")
5952

60-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0")
61-
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.0")
62-
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.0")
53+
// test
54+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
55+
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
56+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
6357
testImplementation("org.hamcrest:hamcrest-library:2.2")
64-
testImplementation("org.mockito:mockito-junit-jupiter:4.10.0")
65-
testImplementation("org.mockito:mockito-inline:4.10.0")
58+
testImplementation("org.mockito:mockito-junit-jupiter:5.10.0")
59+
60+
// jmh
61+
annotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.35")
6662
testImplementation("org.openjdk.jmh:jmh-core:1.35")
63+
testAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.35")
64+
65+
// lombok
66+
compileOnly("org.projectlombok:lombok:1.18.24")
67+
annotationProcessor("org.projectlombok:lombok:1.18.24")
6768
testCompileOnly("org.projectlombok:lombok:1.18.24")
6869
testAnnotationProcessor("org.projectlombok:lombok:1.18.24")
69-
testAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.35")
7070
}
7171

7272
tasks.withType<JavaCompile> {
@@ -77,17 +77,17 @@ tasks.withType<Test> {
7777
useJUnitPlatform()
7878
testLogging {
7979
events(
80-
TestLogEvent.FAILED,
81-
TestLogEvent.PASSED,
82-
TestLogEvent.SKIPPED
80+
TestLogEvent.FAILED,
81+
TestLogEvent.PASSED,
82+
TestLogEvent.SKIPPED
8383
)
8484
debug {
8585
events(
86-
TestLogEvent.FAILED,
87-
TestLogEvent.PASSED,
88-
TestLogEvent.SKIPPED,
89-
TestLogEvent.STANDARD_OUT,
90-
TestLogEvent.STANDARD_ERROR
86+
TestLogEvent.FAILED,
87+
TestLogEvent.PASSED,
88+
TestLogEvent.SKIPPED,
89+
TestLogEvent.STANDARD_OUT,
90+
TestLogEvent.STANDARD_ERROR
9191
)
9292
showStackTraces = true
9393
exceptionFormat = TestExceptionFormat.FULL
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

java-algorithm/src/main/java/com/example/algorithm/graph/Prim.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.example.algorithm.graph;
22

3+
import com.google.common.base.Objects;
4+
35
import java.util.HashSet;
46
import java.util.LinkedHashSet;
57
import java.util.PriorityQueue;
@@ -126,13 +128,32 @@ public void addEdge(Edge edge) {
126128
}
127129
}
128130

129-
public static class Vertex {
131+
public static class Vertex implements Comparable<Vertex> {
130132
char key;
131133
Set<Edge> edges = new HashSet<>();
132134

133135
public Vertex(char key) {
134136
this.key = key;
135137
}
138+
139+
@Override
140+
public int compareTo(Vertex other) {
141+
return Character.compare(this.key, other.key);
142+
}
143+
144+
@Override
145+
public boolean equals(Object o) {
146+
if (this == o) return true;
147+
if (o == null || getClass() != o.getClass()) return false;
148+
Vertex vertex = (Vertex) o;
149+
return key == vertex.key
150+
&& Objects.equal(edges, vertex.edges);
151+
}
152+
153+
@Override
154+
public int hashCode() {
155+
return Objects.hashCode(key);
156+
}
136157
}
137158

138159
public static class Edge implements Comparable<Edge> {
@@ -148,7 +169,22 @@ public Edge(Vertex source, Vertex sink, int weight) {
148169

149170
@Override
150171
public int compareTo(Edge other) {
151-
return Integer.compare(weight, other.weight);
172+
return Integer.compare(this.weight, other.weight);
173+
}
174+
175+
@Override
176+
public boolean equals(Object o) {
177+
if (this == o) return true;
178+
if (o == null || getClass() != o.getClass()) return false;
179+
Edge edge = (Edge) o;
180+
return weight == edge.weight
181+
&& Objects.equal(source, edge.source)
182+
&& Objects.equal(sink, edge.sink);
183+
}
184+
185+
@Override
186+
public int hashCode() {
187+
return Objects.hashCode(source, sink, weight);
152188
}
153189
}
154190
}

java-algorithm/src/test/java/com/example/algorithm/graph/PrimTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.junit.jupiter.api.BeforeEach;
55
import org.junit.jupiter.api.Test;
66

7-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
7+
import java.util.Arrays;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
810

911
class PrimTest {
1012
Prim.Graph graph;
@@ -69,14 +71,22 @@ void tearDown() {
6971
@Test
7072
void primAlgorithmVertex() {
7173
var expected = new Prim.Vertex[]{vertexA, vertexB, vertexC, vertexI, vertexF, vertexG, vertexH, vertexD, vertexE};
72-
var actual = Prim.primAlgorithmVertex(graph, vertexA);
73-
assertArrayEquals(expected, actual);
74+
var vertices = Prim.primAlgorithmVertex(graph, vertexA);
75+
Arrays.sort(expected);
76+
Arrays.sort(vertices);
77+
for (int i = 0; i < expected.length; i++) {
78+
assertEquals(expected[i].key, vertices[i].key);
79+
}
7480
}
7581

7682
@Test
7783
void primAlgorithmEdge() {
7884
var expected = new Prim.Edge[]{edgeAB, edgeBC, edgeCI, edgeCF, edgeFG, edgeGH, edgeCD, edgeDE};
79-
var actual = Prim.primAlgorithmEdge(graph, vertexA);
80-
assertArrayEquals(expected, actual);
85+
var edges = Prim.primAlgorithmEdge(graph, vertexA);
86+
Arrays.sort(expected);
87+
Arrays.sort(edges);
88+
for (int i = 0; i < expected.length; i++) {
89+
assertEquals(expected[i].weight, edges[i].weight);
90+
}
8191
}
8292
}

0 commit comments

Comments
 (0)