#include <lepto/string.h>
#include <lepto/list.h>
#include <lepto/ring.h>
#include <lepto/log.h>
#include <lepto/lepto.h>      // address_t
#include <lepto/logoutput_console.h>

#define keepFunc( name ) keeperPointer+=(address_t)& name;
static address_t keeperPointer=0;

CLogOutput *stdLogOutput;


int validateList()
{
   CList<int> list;

   lHint << "Checking adding to list";
   for(int i1=0; i1<0x10; i1++)
      list << i1;

   lAssert( list.count() == 0x10 );
   for(int i1=0; i1<0x10; i1++)
   {
      lHint << i1 << ": " << list.at(i1);
      lAssert ( list.at(i1) == i1 );
   }
   return(0);
}


int validateRing()
{
   CRing<float> ring(4);
   ring.setVolatile(true);

   for(int i1=0; i1<4; i1++)
      ring.putEntry(i1+1);

   lHint << "IV: " << ring.crossfoot();
   lAssert ( ring.crossfoot() == ( (1.0+2.0+3.0+4.0)/4.0) );

   for(int i1=0; i1<5; i1++)
      ring.putEntry(i1+1);

   lHint << "IV: " << ring.crossfoot();
   lHint << "SV: " << ( (    2.0+3.0+4.0+5.0 ) / 4.0 );
   lAssert ( ring.crossfoot() == ( (    2.0+3.0+4.0+5.0)/4.0) );

   return(0);
}

extern "C" int _isatty(int file);
extern "C" int _fstat(int file, struct stat *st);

int main()
{
   stdLogOutput=new CLogOutputConsole( true );

   keepFunc( _isatty);
   keepFunc( _fstat);

   lHint << "Validate CList";
   validateList();

   lHint << "Validate CRing";
   validateRing();

   lHint << "All checks performed, no pproblem detected";


   return 0;
}

