Fix test case, Remove debug comments

This commit is contained in:
MrLetsplay 2024-06-17 22:35:56 +02:00
parent 594e26ddf5
commit f918093097
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
4 changed files with 4 additions and 23 deletions

View File

@ -53,8 +53,6 @@ public class SharedDocument implements MessageListener {
Change[] changes = new Change[bytes.length]; Change[] changes = new Change[bytes.length];
for(int i = 0; i < bytes.length; i++) { for(int i = 0; i < bytes.length; i++) {
// System.out.println(charBefore);
// System.out.println(charAfter);
Identifier[] newPos = Util.generatePositionBetween(charBefore.position(), charAfter.position(), site); Identifier[] newPos = Util.generatePositionBetween(charBefore.position(), charAfter.position(), site);
lamport++; lamport++;
Char ch = new Char(newPos, lamport, bytes[i]); Char ch = new Char(newPos, lamport, bytes[i]);
@ -63,11 +61,6 @@ public class SharedDocument implements MessageListener {
charBefore = ch; charBefore = ch;
} }
// System.out.println("!! New changes:");
// for(Change c : changes) {
// System.out.println(c);
// }
return changes; return changes;
} }

View File

@ -30,7 +30,6 @@ public class Util {
System.err.println("Got invalid positions"); System.err.println("Got invalid positions");
System.err.println(Arrays.toString(before)); System.err.println(Arrays.toString(before));
System.err.println(Arrays.toString(after)); System.err.println(Arrays.toString(after));
Thread.dumpStack();
throw new IllegalArgumentException("before must be strictly less than after"); throw new IllegalArgumentException("before must be strictly less than after");
} }

View File

@ -3,8 +3,6 @@ package me.mrletsplay.shareclientcore;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import me.mrletsplay.shareclientcore.document.Identifier; import me.mrletsplay.shareclientcore.document.Identifier;
@ -121,7 +119,7 @@ public class DecimalTest {
Identifier[] a = { new Identifier(1, 0), new Identifier(2, 1) }; Identifier[] a = { new Identifier(1, 0), new Identifier(2, 1) };
Identifier[] b = { new Identifier(1, 0), new Identifier(2, 2) }; Identifier[] b = { new Identifier(1, 0), new Identifier(2, 2) };
Identifier[] newIdent = Util.generatePositionBetween(a, b, 3); Identifier[] newIdent = Util.generatePositionBetween(a, b, 3);
Identifier[] expected = { new Identifier(1, 0), new Identifier(2, 1), new Identifier(1, 3) }; Identifier[] expected = { new Identifier(1, 0), new Identifier(2, 1), new Identifier(0, 3), new Identifier(1, 3) };
assertArrayEquals(expected, newIdent); assertArrayEquals(expected, newIdent);
} }
@ -145,8 +143,9 @@ public class DecimalTest {
public void testGeneratePositionEdgeCase1() { public void testGeneratePositionEdgeCase1() {
Identifier[] a = { new Identifier(3, 0), new Identifier(1, 1) }; Identifier[] a = { new Identifier(3, 0), new Identifier(1, 1) };
Identifier[] b = { new Identifier(3, 1) }; Identifier[] b = { new Identifier(3, 1) };
Identifier[] sus = Util.generatePositionBetween(a, b, 1); Identifier[] newIdent = Util.generatePositionBetween(a, b, 1);
System.out.println(Arrays.toString(sus)); Identifier[] expected = { new Identifier(3, 0), new Identifier(1, 1), new Identifier(1, 1) };
assertArrayEquals(expected, newIdent);
} }
} }

View File

@ -53,12 +53,10 @@ public class SharingTest {
private void performRandomEdit(Random r, SharedDocument document) { private void performRandomEdit(Random r, SharedDocument document) {
if(document.getContents().length == 0 || r.nextBoolean()) { if(document.getContents().length == 0 || r.nextBoolean()) {
// System.out.println("INSERT");
char[] insert = new char[r.nextInt(16)]; char[] insert = new char[r.nextInt(16)];
for(int j = 0; j < insert.length; j++) insert[j] = CHARS.charAt(r.nextInt(CHARS.length())); for(int j = 0; j < insert.length; j++) insert[j] = CHARS.charAt(r.nextInt(CHARS.length()));
document.localInsert(r.nextInt(document.getContents().length + 1), String.valueOf(insert)); document.localInsert(r.nextInt(document.getContents().length + 1), String.valueOf(insert));
}else { }else {
// System.out.println("DELETE");
int len = document.getContents().length; int len = document.getContents().length;
int idx = r.nextInt(len); int idx = r.nextInt(len);
int n = r.nextInt(Math.min(16, len - idx)) + 1; int n = r.nextInt(Math.min(16, len - idx)) + 1;
@ -83,9 +81,6 @@ public class SharingTest {
Random r = new Random(0); Random r = new Random(0);
for(int i = 0; i < 10_000; i++) { for(int i = 0; i < 10_000; i++) {
performRandomEdit(r, r.nextBoolean() ? sharedA : sharedB); performRandomEdit(r, r.nextBoolean() ? sharedA : sharedB);
// System.out.println("A: " + sharedA.getContentsAsString());
// System.out.println("B: " + sharedB.getContentsAsString());
assertEquals(sharedA.getContentsAsString(), sharedB.getContentsAsString()); assertEquals(sharedA.getContentsAsString(), sharedB.getContentsAsString());
} }
} }
@ -109,22 +104,17 @@ public class SharingTest {
Random r = new Random(2); Random r = new Random(2);
for(int i = 0; i < 1000; i++) { for(int i = 0; i < 1000; i++) {
// System.out.println(i);
// Perform some random edits // Perform some random edits
for(int j = 0; j < 100; j++) { for(int j = 0; j < 100; j++) {
boolean bEdit = r.nextBoolean(); boolean bEdit = r.nextBoolean();
// System.out.println(bEdit ? "B EDIT" : "A EDIT");
performRandomEdit(r, bEdit ? sharedA : sharedB); performRandomEdit(r, bEdit ? sharedA : sharedB);
} }
// Randomly interleave messages // Randomly interleave messages
while(!messagesA.isEmpty() || !messagesB.isEmpty()) { while(!messagesA.isEmpty() || !messagesB.isEmpty()) {
if(messagesB.isEmpty() || (!messagesA.isEmpty() && r.nextBoolean())) { if(messagesB.isEmpty() || (!messagesA.isEmpty() && r.nextBoolean())) {
// System.out.println("A -> B: " + messagesA.get(0));
b.receive(messagesA.remove(0)); b.receive(messagesA.remove(0));
}else { }else {
// System.out.println("B -> A: " + messagesB.get(0));
a.receive(messagesB.remove(0)); a.receive(messagesB.remove(0));
} }
} }