-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added quickcheck tests (test oracle)
- Loading branch information
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/exchange/core2/collections/art/testoracle/ManualTestOracle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/exchange/core2/collections/art/testoracle/QuickcheckTestOracle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |