PNCounter implements CrdtCounter<Long, PNCounter> { @Override public Long value() { long pValue = (long) pCount.value(); long nValue = (long) nCount.value(); return pValue - nValue; } PNCounter(Map<String, Long> pCounters, Map<String, Long> nCounters);  PNCounter(PNCounter starter, Builder builder);  PNCounter(Builder builder);  PNCounter(GossipManager manager);  PNCounter(PNCounter starter, PNCounter other); @Override PNCounter merge(PNCounter other); @Override Long value(); @Override PNCounter optimize(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void existanceTest() { PNCounter counter = new PNCounter(mockManagers.get(0)); Assert.assertEquals(0, (long) counter.value()); }
@Test public void localOperationTest() { PNCounter counter = new PNCounter(mockManagers.get(0)); Assert.assertEquals(0, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).increment(5L)); Assert.assertEquals(5, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).increment(4L)); Assert.assertEquals(9, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).decrement(3L)); Assert.assertEquals(6, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).decrement(12L)); Assert.assertEquals(-6, (long) counter.value()); }
@Test public void oddballLocalOperationTest() { PNCounter counter = new PNCounter(mockManagers.get(0)); Assert.assertEquals(0, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).increment(-5L)); Assert.assertEquals(-5, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).increment(4L)); Assert.assertEquals(-1, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).decrement(-3L)); Assert.assertEquals(2, (long) counter.value()); counter = new PNCounter(counter, new PNCounter.Builder(mockManagers.get(0)).decrement(-12L)); Assert.assertEquals(14, (long) counter.value()); }