/////////////////////////////////////////////////////////////////////////////
//
// File:       zmtBlockTest.cc
// Purpose:    Test platform for the class template Block<T,N>
// Author:     Marc Paterno, adapted for Zoom by Walter Brown
//
/////////////////////////////////////////////////////////////////////////////


#include "ZMutility/ZMenvironment.h"
#include "ZMtools/Block.h"
#include <iostream>
#include <string>
#include <cassert>
#include <utility>
#include <algorithm>
#include <iterator>
#include <sstream>

class Trivial {};


int  main( int argc, char const * argv[] )  {

  ZM_USING_NAMESPACE( std )
  ZM_USING_NAMESPACE( zmt )

  std::cout << argv[0] << std::endl;

  Block<int,3>  a = { 1, 2, 3 };
  assert( a.size() == 3 );
  assert( a.empty() == false );
  assert( a.max_size() == 3 );
  assert( a[0] == 1 );
  assert( a[1] == 2 );
  assert( a[2] == 3 );

  Block<int,3>  b( a );
  assert( a == b );
  Block<int,3>  c = { 1, 2, 4 };
  assert( !(a == c) );
  assert( a < c );

  Block<Trivial,1>  triv;
  assert( triv.empty() == false );

  Block<float,0>  f;
#ifndef DEFECT_NO_PARTIAL_SPECIALIZATION
  assert( f.empty() );
#else
  std::cout << "This platform does not support partial specialization.";
  std::cout << std::endl;
  std::cout << "Thus Block<T,0> may behave inadequately";
  std::cout << std::endl;
#endif

  // Uncomment the use of f[0] to test that use of operator[] on a 
  // zero-size Block<> produces a compilation error, as required.

  // float x = f[0];

  std::ostringstream buffer;
  std::copy( a.begin(), a.end(), std::ostream_iterator<int>(buffer, " ") );
  assert( buffer.str() == "1 2 3 " ); // note the trailing space

  std::cout << "OK" << std::endl;
  return 0;  

}  // main()
