Retrieve the set of unseen connection numbers from a connection

window.
This commit is contained in:
akwizgran
2011-08-11 13:58:11 +01:00
parent ac4521152f
commit 0e6638bad6
3 changed files with 69 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
package net.sf.briar.transport;
import java.util.Collection;
import junit.framework.TestCase;
import org.junit.Test;
@@ -71,7 +73,7 @@ public class ConnectionWindowImplTest extends TestCase {
}
@Test
public void testCannotSetSameValueTwice() {
public void testCannotSetSeenTwice() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
w.setSeen(15);
try {
@@ -79,4 +81,43 @@ public class ConnectionWindowImplTest extends TestCase {
fail();
} catch(IllegalArgumentException expected) {}
}
@Test
public void testGetUnseenConnectionNumbers() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
Collection<Long> unseen = w.getUnseenConnectionNumbers();
assertEquals(16, unseen.size());
for(int i = 0; i < 16; i++) {
assertTrue(unseen.contains(Long.valueOf(i)));
assertFalse(w.isSeen(i));
}
w.setSeen(3);
w.setSeen(4);
// Centre is 5; window should cover 0 to 20, inclusive, with two seen
unseen = w.getUnseenConnectionNumbers();
assertEquals(19, unseen.size());
for(int i = 0; i < 21; i++) {
if(i == 3 || i == 4) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {
assertTrue(unseen.contains(Long.valueOf(i)));
assertFalse(w.isSeen(i));
}
}
w.setSeen(19);
// Centre is 20; window should cover 4 to 35, inclusive, with two seen
unseen = w.getUnseenConnectionNumbers();
assertEquals(30, unseen.size());
for(int i = 4; i < 36; i++) {
if(i == 4 || i == 19) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {
assertTrue(unseen.contains(Long.valueOf(i)));
assertFalse(w.isSeen(i));
}
}
}
}