From 29bb48a8cc8122871d8728be6fd8b853e52568bd Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Wed, 23 Jan 2019 16:14:16 -0600 Subject: Interim checkin. Network packet processing not done yet. --- src/test/NetworkPacketTest.java | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/NetworkPacketTest.java (limited to 'src/test') 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 requests = new ArrayList<>(); + ArrayList responses = NetworkPacket.processRequests(requests, buf); + assertEquals(0, responses.size()); + } + + @Test + void test1() { + int bufferMaxSize = 1; + NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize); + ArrayList requests = new ArrayList<>(); + requests.add(new NetworkPacket.Request(0, 1)); + ArrayList 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 requests = new ArrayList<>(); + requests.add(new NetworkPacket.Request(0, 1)); + requests.add(new NetworkPacket.Request(0, 1)); + ArrayList 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 requests = new ArrayList<>(); + requests.add(new NetworkPacket.Request(0, 1)); + requests.add(new NetworkPacket.Request(1, 1)); + ArrayList 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); + } +} -- cgit v1.2.3