diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/NetworkPacketTest.java | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/src/test/NetworkPacketTest.java b/src/test/NetworkPacketTest.java index fca3d60..aecd968 100644 --- a/src/test/NetworkPacketTest.java +++ b/src/test/NetworkPacketTest.java @@ -6,7 +6,7 @@ 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 { +class NetworkPacketTest { @Test void test() { int bufferMaxSize = 1; @@ -56,4 +56,111 @@ public class NetworkPacketTest { assertFalse(responses.get(1).dropped); assertEquals(1, responses.get(1).startTime); } + + @Test + void test4() { + int bufferMaxSize = 1; + NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize); + ArrayList<NetworkPacket.Request> requests = new ArrayList<>(); + requests.add(new NetworkPacket.Request(1, 0)); + ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf); + assertEquals(1, responses.size()); + assertEquals(1, responses.get(0).startTime); + } + + @Test + void test5() { + 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, 0)); + ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf); + assertEquals(2, responses.size()); + assertEquals(0, responses.get(0).startTime); + assertEquals(-1, responses.get(1).startTime); + } + + @Test + void test6() { + int bufferMaxSize = 2; + 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()); + assertEquals(0, responses.get(0).startTime); + assertEquals(1, responses.get(1).startTime); + } + + @Test + void test7() { + int bufferMaxSize = 2; + 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)); + requests.add(new NetworkPacket.Request(0, 1)); + ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf); + assertEquals(3, responses.size()); + assertEquals(0, responses.get(0).startTime); + assertEquals(1, responses.get(1).startTime); + assertEquals(-1, responses.get(2).startTime); + } + + @Test + void test8() { + int bufferMaxSize = 3; + NetworkPacket.Buffer buf = new NetworkPacket.Buffer(bufferMaxSize); + ArrayList<NetworkPacket.Request> requests = new ArrayList<>(); + requests.add(new NetworkPacket.Request(0, 2)); + requests.add(new NetworkPacket.Request(1, 2)); + requests.add(new NetworkPacket.Request(2, 2)); + requests.add(new NetworkPacket.Request(3, 2)); + requests.add(new NetworkPacket.Request(4, 2)); + requests.add(new NetworkPacket.Request(5, 2)); + ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf); + assertEquals(6, responses.size()); + assertEquals(0, responses.get(0).startTime); + assertEquals(2, responses.get(1).startTime); + assertEquals(4, responses.get(2).startTime); + assertEquals(6, responses.get(3).startTime); + assertEquals(8, responses.get(4).startTime); + assertEquals(-1, responses.get(5).startTime); + } + + @Test + void test9() { + 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)); + requests.add(new NetworkPacket.Request(2, 1)); + requests.add(new NetworkPacket.Request(3, 1)); + requests.add(new NetworkPacket.Request(3, 1)); + ArrayList<NetworkPacket.Response> responses = NetworkPacket.processRequests(requests, buf); + assertEquals(5, responses.size()); + assertEquals(0, responses.get(0).startTime); + assertEquals(1, responses.get(1).startTime); + assertEquals(2, responses.get(2).startTime); + assertEquals(3, responses.get(3).startTime); + assertEquals(-1, responses.get(4).startTime); + } + + @Test + void test10() { + 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(2, 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(2, responses.get(1).startTime); + } } |