#include "TestVectorsTest.h"

#include "../CellularAutomaton.h"
#include "../TestVectors.h"
#include <cstdio>

unit_test::TestVectorsTest::TestVectorsTest() :
    UnitTest(), chromosome( NULL ) { /* Empty */ }
unit_test::TestVectorsTest::~TestVectorsTest() {
  if ( chromosome )
    delete[] chromosome;
}

unsigned int unit_test::TestVectorsTest::setChromosomeRule30() {
  if ( chromosome )
    delete[] chromosome;
  unsigned int n = 5u * 2u;
  unsigned int middle = ( n / 2u ) - 1u;
  chromosome = new AlleleType[n];
  for ( unsigned int i = 0u; i < n; i += 2u ) {
    chromosome[i] = ( i == middle ) ?
                    static_cast<AlleleType>( 1 ) : static_cast<AlleleType>( 0 );
    chromosome[i+1u] = static_cast<AlleleType>( 30 );
  }
  return n;
}

int unit_test::TestVectorsTest::run( int argc, char *argv[] ) {
  unsigned int n = setChromosomeRule30();
  CellularAutomaton ca( chromosome, n );
  std::string fn = "c17.bench.vct";
  TestVectors tv( fn );

  unsigned int matches = tv.countMatches( &ca, 10u );
  std::printf( "---Found %2d matches during %d iterations\n", matches, ca.getIteration() );

  return 0;
}

int main( int argc, char *argv[] ) {
  unit_test::TestVectorsTest test;
  return test.run( argc, argv );
}
