Skip to content

Commit

Permalink
added quickcheck tests (test oracle)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpawlucz committed Jul 26, 2020
1 parent d4b3ccd commit 1ed0dfc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,18 @@
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.pholser</groupId>
<artifactId>junit-quickcheck-core</artifactId>
<version>0.9.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pholser</groupId>
<artifactId>junit-quickcheck-generators</artifactId>
<version>0.9.3</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private void remove(long key) {
}


private static <K, V> void checkStreamsEqual(final Stream<Map.Entry<K, V>> entry, final Stream<Map.Entry<K, V>> origEntry) {
public static <K, V> void checkStreamsEqual(final Stream<Map.Entry<K, V>> entry, final Stream<Map.Entry<K, V>> origEntry) {
final Iterator<Map.Entry<K, V>> iter = entry.iterator();
final Iterator<Map.Entry<K, V>> origIter = origEntry.iterator();
while (iter.hasNext() && origIter.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package exchange.core2.collections.art.testoracle;

import exchange.core2.collections.art.LongAdaptiveRadixTreeMap;
import exchange.core2.collections.art.LongAdaptiveRadixTreeMapTest;
import org.junit.Test;

import java.util.*;

public class ManualTestOracle {

@Test
public void shouldMaintainOrder(){
List<Long> arrayOfLong = Arrays.asList(-4429196230935817217L, 2967034165565055791L, 3969304394476946051L, 5502623383577302445L);
// List<Long> arrayOfLong = Arrays.asList(1L, 2L, -3L, 4L, 2967034165565055791L, 3969304394476946051L, 5502623383577302445L);

LongAdaptiveRadixTreeMap<String> testedMap = new LongAdaptiveRadixTreeMap<>();
TreeMap<Long, String> oracleMap = new TreeMap<>();

for (Long key : arrayOfLong) {
String value = String.valueOf(key);
oracleMap.put(key, value);
testedMap.put(key, value);
}

System.out.println("\norig");
printEntries(oracleMap.entrySet());

System.out.println("\ntested");
printEntries(testedMap.entriesList());

System.out.println("\n" + testedMap.printDiagram());

LongAdaptiveRadixTreeMapTest.checkStreamsEqual(testedMap.entriesList().stream(), oracleMap.entrySet().stream());
}

private void printEntries(Collection<Map.Entry<Long, String>> entries) {
for (Map.Entry<Long, String> longStringEntry : entries) {
System.out.println(longStringEntry.getKey() + ": " + longStringEntry.getValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package exchange.core2.collections.art.testoracle;

import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.generator.InRange;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import exchange.core2.collections.art.LongAdaptiveRadixTreeMap;
import exchange.core2.collections.art.LongAdaptiveRadixTreeMapTest;
import org.junit.runner.RunWith;

import java.util.List;
import java.util.TreeMap;

@RunWith(JUnitQuickcheck.class)
public class QuickcheckTestOracle {

@Property(trials = 1500)
public void shouldEntriesMaintainCorrectOrderMixedSignValues(List<Long> arrayOfLong){
shouldEntriesMaintainCorrectOrder(arrayOfLong);
}

@Property(trials = 1500)
public void shouldEntriesMaintainCorrectOrderAllNegativeValues(List<@InRange(max = "0") Long> arrayOfLong){
shouldEntriesMaintainCorrectOrder(arrayOfLong);
}

@Property(trials = 1500)
public void shouldEntriesMaintainCorrectOrderAllPositiveValues(List<@InRange(min = "0") Long> arrayOfLong){
shouldEntriesMaintainCorrectOrder(arrayOfLong);
}

private void shouldEntriesMaintainCorrectOrder(List<Long> arrayOfLong) {
LongAdaptiveRadixTreeMap<String> testedMap = new LongAdaptiveRadixTreeMap<>();
TreeMap<Long, String> oracleMap = new TreeMap<>();

for (Long key : arrayOfLong) {
String value = String.valueOf(key);
oracleMap.put(key, value);
testedMap.put(key, value);
}

LongAdaptiveRadixTreeMapTest.checkStreamsEqual(testedMap.entriesList().stream(), oracleMap.entrySet().stream());
}

}

0 comments on commit 1ed0dfc

Please sign in to comment.