<commit_before>/**
 * @file FixedPriorityQueue_test.cpp
 * @brief Unit tests for the FixedPriorityQueue class.
 * @author <NAME> <<EMAIL>>
 * Copyright 2017, Solid Lake LLC
 * @version 1
 * @date 2017-10-20
 */



#include "UnitTest.hpp"
#include "FixedPriorityQueue.hpp"


namespace sl
{


UNITTEST(FixedPriortyQueue, AddPopInOrder)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  for (int i = 0; i < 10; ++i) {
    int const num = pq.pop();
    testEqual(num, i);
  }
}


UNITTEST(FixedPriortyQueue, AddPeek)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  testEqual(pq.peek(), 0);
}


UNITTEST(FixedPriortyQueue, AddMax)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  testEqual(pq.max(), 1.0);
}


UNITTEST(FixedPriortyQueue, AddContains)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.add(1.0/(i+1), i);
    }
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      testTrue(pq.contains(i));
    } else {
      testFalse(pq.contains(i));
    }
  }

}


UNITTEST(FixedPriortyQueue, AddUpdate)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.update(i, i);
    }
  }

  // verify top element
  testEqual(pq.max(), 9);
  testEqual(pq.peek(), 9);

  float lastPriority = pq.max();
  for (int i = 0; i < 10; ++i) {
    float const newPriority = pq.max();
    int const x = pq.pop();

    // verify we're getting them in order
    testLessOrEqual(newPriority, lastPriority);

    // verify we have the right priority
    if (x % 3 == 0) {
      testEqual(newPriority, x);
    } else {
      testEqual(newPriority, static_cast<float>(1.0/(x+1)));
    }

    lastPriority = newPriority;
  }
}

UNITTEST(FixedPriortyQueue, UpdateByDelta)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(i, i);
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.updateByDelta(i, i);
    }
  }

  // verify top element
  testEqual(pq.max(), 18);
  testEqual(pq.peek(), 9);

  float lastPriority = pq.max();
  for (int i = 0; i < 10; ++i) {
    float const newPriority = pq.max();
    int const x = pq.pop();

    // verify we're getting them in order
    testLessOrEqual(newPriority, lastPriority);

    // verify we have the right priority
    if (x % 3 == 0) {
      testEqual(newPriority, static_cast<float>(x*2));
    } else {
      testEqual(newPriority, static_cast<float>(x));
    }

    lastPriority = newPriority;
  }
}




UNITTEST(FixedPriortyQueue, AddPopReverseOrder)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(i/10.0, i);
  }

  for (int i = 10; i > 0;) {
    --i;
    int const num = pq.pop();<commit_msg>Improve robustness of FixedPriorityQueue tests<commit_after>/**
 * @file FixedPriorityQueue_test.cpp
 * @brief Unit tests for the FixedPriorityQueue class.
 * @author <NAME> <<EMAIL>>
 * Copyright 2017, Solid Lake LLC
 * @version 1
 * @date 2017-10-20
 */



#include "UnitTest.hpp"
#include "FixedPriorityQueue.hpp"


namespace sl
{


UNITTEST(FixedPriortyQueue, AddPopInOrder)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  for (int i = 0; i < 10; ++i) {
    int const num = pq.pop();
    testEqual(num, i);
  }
}


UNITTEST(FixedPriortyQueue, AddPeek)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  testEqual(pq.peek(), 0);
}


UNITTEST(FixedPriortyQueue, AddMax)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  testEqual(pq.max(), 1.0);
}


UNITTEST(FixedPriortyQueue, AddContains)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.add(1.0/(i+1), i);
    }
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      testTrue(pq.contains(i));
    } else {
      testFalse(pq.contains(i));
    }
  }

}


UNITTEST(FixedPriortyQueue, AddUpdate)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(1.0/(i+1), i);
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.update(i, i);
    }
  }

  // verify top element
  testEqual(pq.max(), 9);
  testEqual(pq.peek(), 9);

  float lastPriority = pq.max();
  for (int i = 0; i < 10; ++i) {
    float const newPriority = pq.max();
    int const x = pq.pop();

    // verify we're getting them in order
    testLessOrEqual(newPriority, lastPriority);

    // verify we have the right priority
    if (x % 3 == 0) {
      testEqual(newPriority, x);
    } else {
      testEqual(newPriority, static_cast<float>(1.0/(x+1)));
    }

    lastPriority = newPriority;
  }
}

UNITTEST(FixedPriortyQueue, UpdateByDelta)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(-i, i);
  }

  for (int i = 0; i < 10; ++i) {
    if (i % 3 == 0) {
      pq.updateByDelta(2*i, i);
    }
  }

  // verify top element
  testEqual(pq.max(), 9);
  testEqual(pq.peek(), 9);

  float lastPriority = pq.max();
  for (int i = 0; i < 10; ++i) {
    float const newPriority = pq.max();
    int const x = pq.pop();

    // verify we're getting them in order
    testLessOrEqual(newPriority, lastPriority);

    // verify we have the right priority
    if (x % 3 == 0) {
      testEqual(newPriority, static_cast<float>(x));
    } else {
      testEqual(newPriority, static_cast<float>(-x));
    }

    lastPriority = newPriority;
  }
}




UNITTEST(FixedPriortyQueue, AddPopReverseOrder)
{
  FixedPriorityQueue<float, int> pq(10);

  for (int i = 0; i < 10; ++i) {
    pq.add(i/10.0, i);
  }

  for (int i = 10; i > 0;) {
    --i;
    int const num = pq.pop();
{'fraction_non_alphanumeric': 0.17851184517851185, 'fraction_numerical': 0.036870203536870205, 'mean_word_length': 2.6267392619479732, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1876636', 'n_tokens_mistral': 2687, 'n_tokens_neox': 2394, 'n_words': 599}