Skip to content

Commit

Permalink
LamportTime 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
EltonCN committed Dec 11, 2024
1 parent bb820c7 commit 06b21b2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String toString()


public static LamportTime synchronize(LogicalTime time0, LogicalTime time1) {
if(!(LogicalTime.class.isInstance(time0) && LogicalTime.class.isInstance(time1))){
if(!(LamportTime.class.isInstance(time0) && LamportTime.class.isInstance(time1))){
throw new IllegalArgumentException("LamportTime can only synchonize LamportTime instances");
}

Expand Down
55 changes: 55 additions & 0 deletions src/test/java/br/unicamp/cst/memorystorage/LamportTimeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package br.unicamp.cst.memorystorage;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -53,5 +56,57 @@ public void synchronizeTest()
assertTrue(time0.lessThan(timeS));
assertTrue(time1.lessThan(timeS));
assertEquals(56, timeS.getTime());

LamportTime timeS2 = LamportTime.synchronize(time1, time0);

assertTrue(time0.lessThan(timeS2));
assertTrue(time1.lessThan(timeS2));
assertEquals(56, timeS2.getTime());
}

@Test
public void equalsTest()
{
LamportTime time0 = new LamportTime(0);
LamportTime time1 = new LamportTime(1);
LamportTime time2 = new LamportTime(1);

assertNotEquals(time0, time1);
assertEquals(time1, time2);
}

@Test
public void lessThanTest()
{
LamportTime time0 = new LamportTime(0);
LamportTime time1 = new LamportTime(1);
LamportTime time2 = new LamportTime(2);

assertTrue(time0.lessThan(time1));
assertFalse(time2.lessThan(time1));
}

@Test
public void synchonizeNonLamportTest()
{
LogicalTime logicalTime = new LogicalTime() {

@Override
public LogicalTime increment() {
throw new UnsupportedOperationException("Unimplemented method 'increment'");
}

@Override
public boolean lessThan(Object o) {
throw new UnsupportedOperationException("Unimplemented method 'lessThan'");
}

};

LamportTime lamportTime = new LamportTime();

assertThrows(IllegalArgumentException.class, () -> LamportTime.synchronize(lamportTime, logicalTime));
assertThrows(IllegalArgumentException.class, () -> LamportTime.synchronize(logicalTime, lamportTime));

}
}

0 comments on commit 06b21b2

Please sign in to comment.