<commit_before>#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
#include <boost/atomic.hpp>
#include <iostream>

#include "AsyncSampleCollector.hpp"
#include "IntegralWorkcontroller.hpp"
#include "FakeBci.hpp"
#include "Sample.hpp"

using namespace std;
using namespace boost;
using namespace boost::lockfree;

BOOST_AUTO_TEST_SUITE(AsyncSampleCollectorTest)

BOOST_AUTO_TEST_CASE(test_create_destroy)
{
  FakeBci fbci;
  Sample<uint32_t>* pProducerSamples = new Sample<uint32_t>[42];
  SampleBuffer<uint32_t> sampleRingBuffer;
  spsc_queue<Sample<uint32_t>*,  capacity<(42 - 1)> > queue;
  IntegralWorkController workController(1);

  AsyncSampleCollector* collector = new AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController, pProducerSamples, &sampleRingBuffer);
  delete collector;
}

BOOST_AUTO_TEST_CASE(test_create_copy)
{
  FakeBci fbci;
  Sample<uint32_t>* pProducerSamples = new Sample<uint32_t>[42];
  SampleBuffer<uint32_t> sampleRingBuffer;
  spsc_queue<Sample<uint32_t>*,  capacity<(42 - 1)> > queue;
  IntegralWorkController workController(1);
  IntegralWorkController workController1(1);

  AsyncSampleCollector c = AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController, pProducerSamples, &sampleRingBuffer);  
  AsyncSampleCollector c1 = AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController1, pProducerSamples, &sampleRingBuffer);  
  AsyncSampleCollector c2(c);
  BOOST_VERIFY(c == c2);
  BOOST_VERIFY(c != c1);
  BOOST_VERIFY(!(c != c2));
  BOOST_VERIFY(!(c == c1));
  c = c1;
  BOOST_VERIFY(c != c2);
  BOOST_VERIFY(c == c1);
  c = c2;
  BOOST_VERIFY(c == c2);
  BOOST_VERIFY(c != c1);  
}


BOOST_AUTO_TEST_SUITE_END()<commit_msg>Added a test of AsyncSampleCollectorTest.operator()()<commit_after>#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
#include <boost/atomic.hpp>
#include <iostream>

#include "AsyncSampleCollector.hpp"
#include "IntegralWorkcontroller.hpp"
#include "FakeBci.hpp"
#include "Sample.hpp"

using namespace std;
using namespace boost;
using namespace boost::lockfree;

BOOST_AUTO_TEST_SUITE(AsyncSampleCollectorTest)

BOOST_AUTO_TEST_CASE(test_create_destroy)
{
  cout << "AsyncSampleCollector.test_create_destroy " << endl;        
  FakeBci fbci;
  Sample<uint32_t>* pProducerSamples = new Sample<uint32_t>[42];
  SampleBuffer<uint32_t> sampleRingBuffer;
  spsc_queue<Sample<uint32_t>*,  capacity<(42 - 1)> > queue;
  IntegralWorkController workController(1);

  AsyncSampleCollector* collector = new AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController, pProducerSamples, &sampleRingBuffer);
  delete collector;
}

BOOST_AUTO_TEST_CASE(test_create_copy)
{
  cout << "AsyncSampleCollector.test_create_copy " << endl;    
  FakeBci fbci;
  Sample<uint32_t>* pProducerSamples = new Sample<uint32_t>[1339];
  SampleBuffer<uint32_t> sampleRingBuffer;
  spsc_queue<Sample<uint32_t>*,  capacity<(1338)> > queue;
  IntegralWorkController workController(1);
  IntegralWorkController workController1(1);

  AsyncSampleCollector c = AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController, pProducerSamples, &sampleRingBuffer);  
  AsyncSampleCollector c1 = AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                            &workController1, pProducerSamples, &sampleRingBuffer);  
  AsyncSampleCollector c2(c);
  BOOST_VERIFY(c == c2);
  BOOST_VERIFY(c != c1);
  BOOST_VERIFY(!(c != c2));
  BOOST_VERIFY(!(c == c1));
  c = c1;
  BOOST_VERIFY(c != c2);
  BOOST_VERIFY(c == c1);
  c = c2;
  BOOST_VERIFY(c == c2);
  BOOST_VERIFY(c != c1);  
}

BOOST_AUTO_TEST_CASE(test_functor)
{
  cout << "AsyncSampleCollector.test_functor " << endl;
  FakeBci fbci;
  Sample<uint32_t>* pProducerSamples = new Sample<uint32_t>[4200];
  SampleBuffer<uint32_t> sampleRingBuffer;
  boost::lockfree::spsc_queue<Sample<uint32_t>* > queue(4200);
  IntegralWorkController workController(1);
  
  AsyncSampleCollector c = AsyncSampleCollector((IBci*)&fbci, (spsc_queue<Sample<uint32_t>* >* )&queue,
                                           &workController, pProducerSamples, &sampleRingBuffer);
 c();
 BOOST_CHECK_EQUAL(1, fbci.mAcquireCount);
 BOOST_CHECK_EQUAL(1, fbci.mChannelsCount);
 BOOST_CHECK_EQUAL(1, fbci.mGetDataCount);
 BOOST_CHECK_EQUAL(pProducerSamples[0].sample(), fbci.mpLastGetData);
 BOOST_CHECK_EQUAL(pProducerSamples[0].length(), fbci.mLastChannels * fbci.mAcquireRet);  
 BOOST_CHECK_EQUAL(1, c.currentSample());
}

BOOST_AUTO_TEST_SUITE_END()
{'fraction_non_alphanumeric': 0.12420837589376915, 'fraction_numerical': 0.025740551583248214, 'mean_word_length': 4.719626168224299, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3081198', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1697, 'n_words': 262}