summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/NetworkPacketTest.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/NetworkPacketTest.java b/src/test/NetworkPacketTest.java
new file mode 100644
index 0000000..fca3d60
--- /dev/null
+++ b/src/test/NetworkPacketTest.java
@@ -0,0 +1,59 @@
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NetworkPacketTest {
+ @Test
+ void test() {
+ int bufferMaxSize = 1;
+ NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize);
+ ArrayList<NetworkPacket.Request> requests = new ArrayList<>();
+ ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf);
+ assertEquals(0, responses.size());
+ }
+
+ @Test
+ void test1() {
+ int bufferMaxSize = 1;
+ NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize);
+ ArrayList<NetworkPacket.Request> requests = new ArrayList<>();
+ requests.add(new NetworkPacket.Request(0, 1));
+ ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf);
+ assertEquals(1, responses.size());
+ assertFalse(responses.get(0).dropped);
+ assertEquals(0, responses.get(0).startTime);
+ }
+
+ @Test
+ void test2() {
+ int bufferMaxSize = 1;
+ NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize);
+ ArrayList<NetworkPacket.Request> requests = new ArrayList<>();
+ requests.add(new NetworkPacket.Request(0, 1));
+ requests.add(new NetworkPacket.Request(0, 1));
+ ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf);
+ assertEquals(2, responses.size());
+ assertFalse(responses.get(0).dropped);
+ assertEquals(0, responses.get(0).startTime);
+ assertTrue(responses.get(1).dropped);
+ }
+
+ @Test
+ void test3() {
+ int bufferMaxSize = 1;
+ NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize);
+ ArrayList<NetworkPacket.Request> requests = new ArrayList<>();
+ requests.add(new NetworkPacket.Request(0, 1));
+ requests.add(new NetworkPacket.Request(1, 1));
+ ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf);
+ assertEquals(2, responses.size());
+ assertFalse(responses.get(0).dropped);
+ assertEquals(0, responses.get(0).startTime);
+ assertFalse(responses.get(1).dropped);
+ assertEquals(1, responses.get(1).startTime);
+ }
+}