mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
refactor
This commit is contained in:
85
app/pom.xml
Normal file
85
app/pom.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<main-class>org.toop.Main</main-class>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<configuration>
|
||||
<excludedGroups>stress</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>${main-class}</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.46.1</version>
|
||||
<configuration>
|
||||
<!-- optional: limit format enforcement to just the files changed by this feature branch -->
|
||||
<ratchetFrom>origin/main</ratchetFrom>
|
||||
<formats>
|
||||
<!-- you can define as many formats as you want, each is independent -->
|
||||
<format>
|
||||
<!-- define the files to apply to -->
|
||||
<includes>
|
||||
<include>.gitattributes</include>
|
||||
<include>.gitignore</include>
|
||||
</includes>
|
||||
<!-- define the steps to apply to those files -->
|
||||
<trimTrailingWhitespace/>
|
||||
<endWithNewline/>
|
||||
<indent>
|
||||
<tabs>true</tabs>
|
||||
<spacesPerTab>4</spacesPerTab>
|
||||
</indent>
|
||||
</format>
|
||||
</formats>
|
||||
<!-- define a language-specific format -->
|
||||
<java>
|
||||
<googleJavaFormat>
|
||||
<version>1.28.0</version>
|
||||
<style>AOSP</style> <!-- GOOGLE (2 indents), AOSP (4 indents) -->
|
||||
<reflowLongStrings>true</reflowLongStrings>
|
||||
<formatJavadoc>true</formatJavadoc>
|
||||
</googleJavaFormat>
|
||||
</java>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 956 B After Width: | Height: | Size: 956 B |
16
framework/pom.xml
Normal file
16
framework/pom.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.2.6.Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
13
framework/src/main/resources/log4j2.xml
Normal file
13
framework/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="debug" name="AppConfig">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%17.17t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
7
games/pom.xml
Normal file
7
games/pom.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</project>
|
||||
13
games/src/main/resources/log4j2.xml
Normal file
13
games/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="debug" name="AppConfig">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%17.17t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.toop.game.tictactoe;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.toop.games.GameBase;
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.toop.game.tictactoe;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.toop.games.Player;
|
||||
86
pom.xml
86
pom.xml
@@ -13,8 +13,6 @@
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<main-class>org.toop.app.Main</main-class>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -96,85 +94,11 @@
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.2.6.Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<configuration>
|
||||
<excludedGroups>stress</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>${main-class}</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.diffplug.spotless</groupId>
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.46.1</version>
|
||||
<configuration>
|
||||
<!-- optional: limit format enforcement to just the files changed by this feature branch -->
|
||||
<ratchetFrom>origin/main</ratchetFrom>
|
||||
<formats>
|
||||
<!-- you can define as many formats as you want, each is independent -->
|
||||
<format>
|
||||
<!-- define the files to apply to -->
|
||||
<includes>
|
||||
<include>.gitattributes</include>
|
||||
<include>.gitignore</include>
|
||||
</includes>
|
||||
<!-- define the steps to apply to those files -->
|
||||
<trimTrailingWhitespace/>
|
||||
<endWithNewline/>
|
||||
<indent>
|
||||
<tabs>true</tabs>
|
||||
<spacesPerTab>4</spacesPerTab>
|
||||
</indent>
|
||||
</format>
|
||||
</formats>
|
||||
<!-- define a language-specific format -->
|
||||
<java>
|
||||
<googleJavaFormat>
|
||||
<version>1.28.0</version>
|
||||
<style>AOSP</style> <!-- GOOGLE (2 indents), AOSP (4 indents) -->
|
||||
<reflowLongStrings>true</reflowLongStrings>
|
||||
<formatJavadoc>true</formatJavadoc>
|
||||
</googleJavaFormat>
|
||||
</java>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<modules>
|
||||
<module>framework</module>
|
||||
<module>games</module>
|
||||
<module>app</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -1,109 +0,0 @@
|
||||
package org.toop.backend;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.toop.backend.tictactoe.TcpServer;
|
||||
|
||||
class TcpServerTest {
|
||||
|
||||
static class TestTcpServer extends TcpServer {
|
||||
public TestTcpServer(int port) throws IOException {
|
||||
super(port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Call super.run() in a separate thread if needed
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
|
||||
private TestTcpServer server;
|
||||
private Thread serverThread;
|
||||
private int port = 12345;
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws IOException {
|
||||
server = new TestTcpServer(port);
|
||||
serverThread = new Thread(server::run);
|
||||
serverThread.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void teardown() {
|
||||
server.stop();
|
||||
try {
|
||||
serverThread.join(1000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testServerStartsAndStops() {
|
||||
assertTrue(server.isRunning());
|
||||
server.stop();
|
||||
assertFalse(server.isRunning());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClientMessageEnqueued() throws IOException, InterruptedException {
|
||||
Socket client = new Socket("localhost", port);
|
||||
PrintWriter out = new PrintWriter(client.getOutputStream(), true);
|
||||
|
||||
String message = "hello server";
|
||||
out.println(message);
|
||||
|
||||
String received = server.receivedQueue.poll(1, TimeUnit.SECONDS);
|
||||
assertEquals(message, received);
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendQueueSendsToClient() throws IOException, InterruptedException {
|
||||
Socket client = new Socket("localhost", port);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
||||
|
||||
String msg = "test message";
|
||||
server.sendQueue.put(msg);
|
||||
|
||||
// The server may need some time to deliver
|
||||
String received = in.readLine();
|
||||
assertEquals(msg, received);
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// void testGetNewestCommand() throws InterruptedException {
|
||||
// String command = "move 1 2";
|
||||
// server.receivedQueue.put(command);
|
||||
//
|
||||
// ParsedCommand parsed = server.getNewestCommand();
|
||||
// System.out.println(parsed);
|
||||
// assertNotNull(parsed);
|
||||
// assertEquals(command, parsed.returnMessage); TODO: Test later
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// void testMultipleClients() throws IOException, InterruptedException {
|
||||
// Socket client1 = new Socket("localhost", port);
|
||||
// Socket client2 = new Socket("localhost", port);
|
||||
//
|
||||
// PrintWriter out1 = new PrintWriter(client1.getOutputStream(), true);
|
||||
// PrintWriter out2 = new PrintWriter(client2.getOutputStream(), true);
|
||||
//
|
||||
// out1.println("msg1");
|
||||
// out2.println("msg2");
|
||||
//
|
||||
// assertEquals("msg1", server.receivedQueue.poll(1, TimeUnit.SECONDS));
|
||||
// assertEquals("msg2", server.receivedQueue.poll(1, TimeUnit.SECONDS));
|
||||
//
|
||||
// client1.close();
|
||||
// client2.close();
|
||||
// } TODO: Temp disable for MVP
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.toop.frontend.math;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BoundsTest {
|
||||
|
||||
private Bounds bounds;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bounds = new Bounds(10, 20, 100, 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorAndGetters() {
|
||||
assertEquals(10, bounds.getX());
|
||||
assertEquals(20, bounds.getY());
|
||||
assertEquals(100, bounds.getWidth());
|
||||
assertEquals(50, bounds.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetUpdatesFields() {
|
||||
bounds.set(5, 15, 50, 25);
|
||||
|
||||
assertEquals(5, bounds.getX());
|
||||
assertEquals(15, bounds.getY());
|
||||
assertEquals(50, bounds.getWidth());
|
||||
assertEquals(25, bounds.getHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckInsideBounds() {
|
||||
// Points inside the bounds
|
||||
assertTrue(bounds.check(10, 20)); // top-left corner
|
||||
assertTrue(bounds.check(110, 70)); // bottom-right corner
|
||||
assertTrue(bounds.check(60, 45)); // inside
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckOutsideBounds() {
|
||||
// Points outside the bounds
|
||||
assertFalse(bounds.check(9, 20)); // left
|
||||
assertFalse(bounds.check(10, 19)); // above
|
||||
assertFalse(bounds.check(111, 70)); // right
|
||||
assertFalse(bounds.check(110, 71)); // below
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckOnEdgeBounds() {
|
||||
// Points on the edges should be considered inside
|
||||
assertTrue(bounds.check(10, 20)); // top-left
|
||||
assertTrue(bounds.check(110, 20)); // top-right
|
||||
assertTrue(bounds.check(10, 70)); // bottom-left
|
||||
assertTrue(bounds.check(110, 70)); // bottom-right
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.toop.frontend.math;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ColorTest {
|
||||
|
||||
private Color color;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
color = new Color(0.1f, 0.5f, 0.9f);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorAndGetters() {
|
||||
assertEquals(0.1f, color.r(), 0.0001, "Red component should match");
|
||||
assertEquals(0.5f, color.g(), 0.0001, "Green component should match");
|
||||
assertEquals(0.9f, color.b(), 0.0001, "Blue component should match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDifferentColorValues() {
|
||||
Color c = new Color(1.0f, 0.0f, 0.5f);
|
||||
|
||||
assertEquals(1.0f, c.r(), 0.0001);
|
||||
assertEquals(0.0f, c.g(), 0.0001);
|
||||
assertEquals(0.5f, c.b(), 0.0001);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user