summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHaidong Ji2019-01-23 16:14:16 -0600
committerHaidong Ji2019-01-23 16:14:16 -0600
commit29bb48a8cc8122871d8728be6fd8b853e52568bd (patch)
tree8dbd314ce0526b55a2b19243253a69a5d674b8c6 /src/test
parentca7416db5fb06ab354903ebd57e94cf87797becd (diff)
Interim checkin. Network packet processing not done yet.
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);
+ }
+}