Here are the examples of the java api org.jheaps.Heap taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
95 Examples
19
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSameMinMax() {
Heap<Double> h = new DoubleRadixHeap(1.0, 1.0);
for (int i = 0; i < 15; i++) {
h.insert(1.0);
}
replacedertEquals(15, h.size());
for (int i = 0; i < 15; i++) {
replacedertEquals(1.0, h.deleteMin(), 1e-9);
}
replacedertEquals(0, h.size());
}
19
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed2() {
Heap<Double> h = new DoubleRadixHeap(0.0, 1.0);
Random generator = new Random(2);
h.insert(0.0d);
for (int i = 1; i < SIZE; i++) {
double d = generator.nextDouble();
h.insert(d);
}
Double prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
19
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed1() {
Heap<Double> h = new DoubleRadixHeap(0.0, 1.0);
Random generator = new Random(1);
h.insert(0.0d);
for (int i = 1; i < SIZE; i++) {
double d = generator.nextDouble();
h.insert(d);
}
Double prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
19
Source : MinMaxBinaryArrayHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = IllegalArgumentException.clreplaced)
public void testIllegalSize1() {
Heap<Long> h = createHeap(-1);
h.insert(1L);
}
19
Source : MinMaxBinaryArrayHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = IllegalArgumentException.clreplaced)
public void testIllegalSize() {
Heap<Long> h = createHeap(-4);
h.insert(1L);
}
19
Source : MinMaxBinaryArrayHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = IllegalArgumentException.clreplaced)
public void testIllegalSize2() {
Heap<Long> h = createHeap(Integer.MAX_VALUE - 8);
h.insert(1L);
}
19
Source : HeapifyTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testHeapifySort() {
Random generator = new Random(1);
final int clreplacedes = 8;
Integer[] a = new Integer[SIZE];
for (int i = 0; i < SIZE; i++) {
a[i] = generator.nextInt();
}
@SuppressWarnings("unchecked")
Heap<Integer>[] h = (Heap<Integer>[]) Array.newInstance(Heap.clreplaced, clreplacedes);
h[0] = BinaryArrayHeap.heapify(a);
h[1] = DaryArrayHeap.heapify(2, a);
h[2] = DaryArrayHeap.heapify(3, a);
h[3] = DaryArrayHeap.heapify(4, a);
h[4] = DaryArrayHeap.heapify(5, a);
h[5] = BinaryArrayWeakHeap.heapify(a);
h[6] = BinaryArrayBulkInsertWeakHeap.heapify(a);
h[7] = MinMaxBinaryArrayDoubleEndedHeap.heapify(a);
int elements = SIZE;
Integer prev = null, cur;
while (elements > 0) {
cur = h[0].findMin();
for (int i = 1; i < clreplacedes; i++) {
replacedertEquals(cur.intValue(), h[i].findMin().intValue());
}
for (int i = 0; i < clreplacedes; i++) {
h[i].deleteMin();
}
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
elements--;
}
}
19
Source : HeapifyTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testHeapifySortWithComparator() {
Random generator = new Random(1);
final int clreplacedes = 8;
Integer[] a = new Integer[SIZE];
for (int i = 0; i < SIZE; i++) {
a[i] = generator.nextInt();
}
@SuppressWarnings("unchecked")
Heap<Integer>[] h = (Heap<Integer>[]) Array.newInstance(Heap.clreplaced, clreplacedes);
h[0] = BinaryArrayHeap.heapify(a, comparator);
h[1] = DaryArrayHeap.heapify(2, a, comparator);
h[2] = DaryArrayHeap.heapify(3, a, comparator);
h[3] = DaryArrayHeap.heapify(4, a, comparator);
h[4] = DaryArrayHeap.heapify(5, a, comparator);
h[5] = BinaryArrayWeakHeap.heapify(a, comparator);
h[6] = BinaryArrayBulkInsertWeakHeap.heapify(a, comparator);
h[7] = MinMaxBinaryArrayDoubleEndedHeap.heapify(a, comparator);
int elements = SIZE;
Integer prev = null, cur;
while (elements > 0) {
cur = h[0].findMin();
for (int i = 1; i < clreplacedes; i++) {
replacedertEquals(cur.intValue(), h[i].findMin().intValue());
}
for (int i = 0; i < clreplacedes; i++) {
h[i].deleteMin();
}
if (prev != null) {
replacedertTrue(comparator.compare(prev, cur) <= 0);
}
prev = cur;
elements--;
}
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMaxDifference() {
Heap<Double> h = new DoubleRadixHeap(0.0, Double.MAX_VALUE);
h.insert(0.0);
h.insert(Double.MAX_VALUE);
replacedertEquals(2, h.size());
replacedertEquals(0.0, h.deleteMin(), 1e-9);
replacedertEquals(Double.MAX_VALUE, h.deleteMin(), 1e-9);
replacedertEquals(0, h.size());
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testBug2() {
Heap<Double> h = new DoubleRadixHeap(0.0, 100.0);
h.insert(0.0);
replacedertEquals(0.0, h.findMin(), 1e-9);
replacedertEquals(0.0, h.deleteMin(), 1e-9);
h.insert(15.0);
replacedertEquals(15.0, h.findMin(), 1e-9);
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testVerySmall() {
Heap<Double> h = new DoubleRadixHeap(15.0, 50.5);
h.insert(15.3);
h.insert(50.4);
h.insert(20.999999);
h.insert(50.5);
h.insert(30.3);
h.insert(25.2);
h.insert(17.7777);
replacedertEquals(7, h.size());
replacedertEquals(15.3, h.findMin(), 1e-9);
replacedertEquals(7, h.size());
replacedertEquals(15.3, h.deleteMin(), 1e-9);
replacedertEquals(6, h.size());
replacedertEquals(17.7777, h.findMin(), 1e-9);
replacedertEquals(17.7777, h.deleteMin(), 1e-9);
replacedertEquals(20.999999, h.findMin(), 1e-9);
replacedertEquals(20.999999, h.deleteMin(), 1e-9);
replacedertEquals(25.2, h.findMin(), 1e-9);
replacedertEquals(25.2, h.deleteMin(), 1e-9);
replacedertEquals(30.3, h.findMin(), 1e-9);
replacedertEquals(30.3, h.deleteMin(), 1e-9);
replacedertEquals(50.4, h.findMin(), 1e-9);
replacedertEquals(50.4, h.deleteMin(), 1e-9);
replacedertEquals(50.5, h.findMin(), 1e-9);
replacedertEquals(50.5, h.deleteMin(), 1e-9);
replacedertEquals(h.size(), 0);
replacedertTrue(h.isEmpty());
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void test() {
Heap<Double> h = new DoubleRadixHeap(0.0, SIZE);
for (long i = 0; i < SIZE; i++) {
h.insert((double) i);
replacedertEquals(0d, h.findMin(), 1e-9);
replacedertFalse(h.isEmpty());
replacedertEquals(h.size(), i + 1);
}
for (int i = SIZE - 1; i >= 0; i--) {
replacedertEquals((double) (SIZE - i - 1), h.findMin(), 1e-9);
h.deleteMin();
}
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMultipleDeleteMin() {
final double step = 0.3333;
final double max = 1000.0;
Heap<Double> h = new DoubleRadixHeap(0.0, max);
h.insert(0.0);
double cur = 0.0;
while (cur < max) {
replacedertEquals(cur, h.findMin(), 1e-9);
if (cur + step >= max) {
break;
}
double newCur = cur + step;
h.insert(newCur);
replacedertEquals(cur, h.findMin(), 1e-9);
replacedertEquals(cur, h.deleteMin(), 1e-9);
cur = newCur;
}
}
18
Source : DoubleRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
/*
* Affects version 0.7 of the library.
*/
@Test
public void testBug1() {
Heap<Double> h = new DoubleRadixHeap(0.0, 3.667944409236726);
h.insert(0.0);
replacedertEquals(0.0, h.findMin(), 1e-9);
h.insert(0.9169861023091815);
h.deleteMin();
replacedertEquals(0.9169861023091815, h.findMin(), 1e-9);
h.insert(1.7814708581727154);
h.deleteMin();
replacedertEquals(1.7814708581727154, h.findMin(), 1e-9);
}
18
Source : HeapifyTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
@SuppressWarnings("unchecked")
public void testHeapifyZeroLengthArrayComparator() {
Integer[] a = new Integer[0];
final int nonfixed = 8;
Heap<Integer>[] h = (Heap<Integer>[]) Array.newInstance(Heap.clreplaced, nonfixed);
h[0] = BinaryArrayHeap.heapify(a, comparator);
h[1] = DaryArrayHeap.heapify(2, a, comparator);
h[2] = DaryArrayHeap.heapify(3, a, comparator);
h[3] = DaryArrayHeap.heapify(4, a, comparator);
h[4] = DaryArrayHeap.heapify(5, a, comparator);
h[5] = BinaryArrayWeakHeap.heapify(a, comparator);
h[6] = BinaryArrayBulkInsertWeakHeap.heapify(a, comparator);
h[7] = MinMaxBinaryArrayDoubleEndedHeap.heapify(a, comparator);
for (int i = 0; i < nonfixed; i++) {
replacedertTrue(h[i].isEmpty());
try {
h[i].insert(1);
} catch (IllegalStateException e) {
fail("No!");
}
}
}
18
Source : HeapifyTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
@SuppressWarnings("unchecked")
public void testHeapifyZeroLengthArray() {
Integer[] a = new Integer[0];
final int nonfixed = 8;
Heap<Integer>[] h = (Heap<Integer>[]) Array.newInstance(Heap.clreplaced, nonfixed);
h[0] = BinaryArrayHeap.heapify(a);
h[1] = DaryArrayHeap.heapify(2, a);
h[2] = DaryArrayHeap.heapify(3, a);
h[3] = DaryArrayHeap.heapify(4, a);
h[4] = DaryArrayHeap.heapify(5, a);
h[5] = BinaryArrayWeakHeap.heapify(a);
h[6] = BinaryArrayBulkInsertWeakHeap.heapify(a);
h[7] = MinMaxBinaryArrayDoubleEndedHeap.heapify(a);
for (int i = 0; i < nonfixed; i++) {
replacedertTrue(h[i].isEmpty());
try {
h[i].insert(1);
} catch (IllegalStateException e) {
fail("No!");
}
}
}
17
Source : BinaryTreeSoftHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testComparator() {
Heap<Long> h = new BinaryTreeSoftHeap<Long>(0.5);
replacedertNull(h.comparator());
}
17
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NoSuchElementException.clreplaced)
public void testBadFindMin() {
Heap<Long> h = createHeap();
h.findMin();
}
17
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NullPointerException.clreplaced)
public void testBadInsert() {
Heap<Long> h = createHeap();
h.insert(null);
}
17
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NoSuchElementException.clreplaced)
public void testBadDeleteMin() {
Heap<Long> h = createHeap();
h.deleteMin();
}
17
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testComparator() {
Heap<Long> h = createHeap();
replacedertNull(h.comparator());
}
17
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testComparator() {
Heap<Integer> h = createHeap();
replacedertNull(h.comparator());
}
17
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NoSuchElementException.clreplaced)
public void testBadDeleteMin() {
Heap<Integer> h = createHeap();
h.deleteMin();
}
17
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NullPointerException.clreplaced)
public void testBadInsert() {
Heap<Integer> h = createHeap();
h.insert(null);
}
17
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = NoSuchElementException.clreplaced)
public void testBadFindMin() {
Heap<Integer> h = createHeap();
h.findMin();
}
17
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testComparator() {
Heap<Long> h = new LongRadixHeap(0, 15);
replacedertNull(h.comparator());
}
16
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed1() {
Heap<Long> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextLong());
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
16
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed2() {
Heap<Long> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextLong());
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
16
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSizeOneInitial() {
Heap<Long> h = createHeap(1);
for (long i = 0; i < 15; i++) {
h.insert(i);
}
replacedertEquals(15, h.size());
}
16
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSizeOneInitial() {
Heap<Integer> h = createHeap(1);
for (int i = 0; i < 15; i++) {
h.insert(i);
}
replacedertEquals(15, h.size());
}
16
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed1() {
Heap<Integer> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
16
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed2() {
Heap<Integer> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
16
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test(expected = IllegalArgumentException.clreplaced)
public void testMonotoneNotOkOnLastDeleted() {
Heap<Long> h = new LongRadixHeap(0, 1000);
h.insert(100L);
h.deleteMin();
h.insert(99L);
}
16
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMonotoneOkOnLastDeleted() {
Heap<Long> h = new LongRadixHeap(0, 1000);
h.insert(100L);
replacedertEquals(100L, h.findMin().longValue());
h.insert(99L);
replacedertEquals(99L, h.findMin().longValue());
}
16
Source : IntegerRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMonotoneOkOnLastDeleted() {
Heap<Integer> h = new IntegerRadixHeap(0, 1000);
h.insert(100);
replacedertEquals(100, h.findMin().intValue());
h.insert(99);
replacedertEquals(99, h.findMin().intValue());
}
15
Source : BinaryTreeSoftHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMeldGeneric() {
Heap<Integer> h1 = new BinaryTreeSoftHeap<Integer>(1.0 / (SIZE + 1));
if (h1 instanceof MergeableHeap) {
for (int i = 0; i < SIZE; i++) {
h1.insert(2 * i);
}
Heap<Integer> h2 = new BinaryTreeSoftHeap<Integer>(1.0 / (SIZE + 1));
for (int i = 0; i < SIZE; i++) {
h2.insert(2 * i + 1);
}
((MergeableHeap<Integer>) h1).meld((MergeableHeap<Integer>) h2);
replacedertEquals(h1.size(), SIZE * 2);
replacedertEquals(h2.size(), 0);
Integer prev = null, cur;
while (!h1.isEmpty()) {
cur = h1.findMin();
h1.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
}
15
Source : BinaryTreeSoftHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed1WithComparator() {
Heap<Integer> h = new BinaryTreeSoftHeap<Integer>(1.0 / (SIZE + 1), comparator);
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) >= 0);
}
prev = cur;
}
}
15
Source : BinaryTreeSoftHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort1RandomSeed1() {
Heap<Integer> h = new BinaryTreeSoftHeap<Integer>(1.0 / (SIZE + 1));
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed1() {
Heap<Long> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextLong());
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.findMin();
h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testClear() {
Heap<Long> h = createHeap();
for (long i = 0; i < 15; i++) {
h.insert(i);
}
h.clear();
replacedertEquals(0L, h.size());
replacedertTrue(h.isEmpty());
}
15
Source : AbstractLongHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed2() {
Heap<Long> h = createHeap();
Random generator = new Random(2);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextLong());
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.findMin();
h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testClear() {
Heap<Integer> h = createHeap();
for (int i = 0; i < 15; i++) {
h.insert(i);
}
h.clear();
replacedertEquals(0L, h.size());
replacedertTrue(h.isEmpty());
}
15
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed2() {
Heap<Integer> h = createHeap();
Random generator = new Random(2);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.findMin();
h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : AbstractIntegerHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSortRandomSeed1() {
Heap<Integer> h = createHeap();
Random generator = new Random(1);
for (int i = 0; i < SIZE; i++) {
h.insert(generator.nextInt());
}
Integer prev = null, cur;
while (!h.isEmpty()) {
cur = h.findMin();
h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort2RandomSeed1() {
Heap<Long> h = new LongRadixHeap(0, SIZE + 1);
Random generator = new Random(1);
long[] a = new long[SIZE];
for (int i = 0; i < SIZE; i++) {
a[i] = (long) (SIZE * generator.nextDouble());
}
Arrays.sort(a);
for (int i = 0; i < SIZE; i++) {
h.insert(a[i]);
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testClear() {
Heap<Long> h = new LongRadixHeap(0, 15);
for (long i = 0; i < 15; i++) {
h.insert(i);
}
h.clear();
replacedertEquals(0L, h.size());
replacedertTrue(h.isEmpty());
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSort2RandomSeed2() {
Heap<Long> h = new LongRadixHeap(0, SIZE + 1);
Random generator = new Random(2);
long[] a = new long[SIZE];
for (int i = 0; i < SIZE; i++) {
a[i] = (long) (SIZE * generator.nextDouble());
}
Arrays.sort(a);
for (int i = 0; i < SIZE; i++) {
h.insert(a[i]);
}
Long prev = null, cur;
while (!h.isEmpty()) {
cur = h.deleteMin();
if (prev != null) {
replacedertTrue(prev.compareTo(cur) <= 0);
}
prev = cur;
}
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testSameMinMax() {
Heap<Long> h = new LongRadixHeap(100, 100);
for (int i = 0; i < 15; i++) {
h.insert(100L);
}
replacedertEquals(15, h.size());
for (int i = 0; i < 15; i++) {
replacedertEquals(100L, h.deleteMin().longValue());
}
replacedertEquals(0, h.size());
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testBug2() {
Heap<Long> h = new LongRadixHeap(0L, 100L);
h.insert(0L);
replacedertEquals(0L, h.findMin().longValue());
replacedertEquals(0L, h.deleteMin().longValue());
h.insert(15L);
replacedertEquals(15L, h.findMin().longValue());
}
15
Source : LongRadixHeapTest.java
with Apache License 2.0
from d-michail
with Apache License 2.0
from d-michail
@Test
public void testMultipleDeleteMin() {
final long step = 7;
final long min = 0L;
final long max = 100000L;
Heap<Long> h = new LongRadixHeap(min, max);
h.insert(min);
long cur = min;
while (cur < max) {
replacedertEquals(cur, h.findMin(), 1e-9);
if (cur + step >= max) {
break;
}
long newCur = cur + step;
h.insert(newCur);
replacedertEquals(cur, h.findMin(), 1e-9);
replacedertEquals(cur, h.deleteMin(), 1e-9);
cur = newCur;
}
}
See More Examples