public void testGrowReplaceShrink() {
    Random r = new Random();
    int k = 10000;
    String s = "A";
    double t = 0;
    FibonacciHeap<String> h = new FibonacciHeap<>();
    for (int i = 0; i < (k * 3); ++i) {
      // during first two-thirds, insert
      if (i < (k * 2)) {
        double d = r.nextDouble();
        t += d;
        FibonacciHeapNode<String> n = new FibonacciHeapNode<>(s);
        h.insert(n, d);
      }

      // during last two-thirds, delete (so during middle
      // third, we'll do both insert and delete, interleaved)
      if (i >= k) {
        FibonacciHeapNode<String> n2 = h.removeMin();
        t -= n2.getKey();
      }
    }
    assertTrue(h.isEmpty());

    // tally should come back down to zero, or thereabouts (due to roundoff)
    assertEquals(0.0, t, 0.00001);
  }
 public void testNaNValues() throws ClassNotFoundException, IOException {
   testWriteAndRead(
       new ComplexClass(
           rand.nextInt(),
           rand.nextLong(),
           "hello",
           rand.nextBoolean(),
           Double.NaN,
           rand.nextFloat()));
 }
  public void testWriteRecords() {
    HistoryWriter writer = this.history.getWriter();

    try {
      for (int i = 0; i < 202; i++) {
        writer.addRecord(new String[] {"" + random.nextInt(), "name" + i, i % 2 == 0 ? "m" : "f"});
      }
    } catch (Exception e) {
      fail("Could not write records. Reason: " + e);
    }
  }
 public void testWritingRandomValue() throws ClassNotFoundException, IOException {
   testWriteAndRead(
       new ComplexClass(
           rand.nextInt(),
           rand.nextLong(),
           Integer.toString(rand.nextInt()),
           rand.nextBoolean(),
           rand.nextDouble(),
           rand.nextFloat()));
 }
  public void testCreateDB() {
    ArrayList<String> al = new ArrayList<String>();

    Iterator<HistoryID> i = this.historyService.getExistingIDs();
    while (i.hasNext()) {
      HistoryID id = i.next();
      String[] components = id.getID();

      if (components.length == 2 && "test".equals(components[0])) {
        al.add(components[1]);
      }
    }

    int count = al.size();
    boolean unique = false;
    String lastComp = null;
    while (!unique) {
      lastComp = Integer.toHexString(random.nextInt());
      for (int j = 0; j < count; j++) {
        if (lastComp.equals(al.get(j))) {
          continue;
        }
      }
      unique = true;
    }

    HistoryID id = HistoryID.createFromRawID(new String[] {"test", lastComp});

    try {
      this.historyService.createHistory(id, recordStructure);
    } catch (Exception e) {
      fail("Could not create database with id " + id + " with error " + e);
    }

    try {
      // after creating, remove it - do not leave content
      this.historyService.purgeLocallyStoredHistory(id);
    } catch (Exception ex) {
      fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
    }
  }
 public void testNullValues() throws ClassNotFoundException, IOException {
   testWriteAndRead(
       new ComplexClass(
           rand.nextInt(), rand.nextLong(), null, rand.nextBoolean(), null, rand.nextFloat()));
 }