/*****************************************************************************
 * $Id: multivar.cc,v 1.1 2006/10/29 23:27:54 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Test of Multivar class.
 *//*
 * LEGAL:	COPYRIGHT (C) 2006 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#define TESTING 1
#include "test.hh"
#include "gfx_types.hh"

/*****************************************************************************
 * Test.
 *****************************************************************************/

namespace gfx {
bool
MultivarTest( void )
{
	Multivar mv;
	if ( ! mv.IfEmpty() ) { Fail(); }

	// Set 1, Remove 1.
	mv.Set( 1 );
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query( 1 ) ) { Fail(); }
	mv.Remove( 1 );
	if ( ! mv.IfEmpty() ) { Fail(); }
	if ( mv.Query( 1 ) ) { Fail(); }

	// Test Clear().
	mv.Set( 0 );
	mv.Clear();
	if ( ! mv.IfEmpty() ) { Fail(); }
	if ( mv.Query( 0 ) ) { Fail(); }

	// Set 2, Add 3.
	mv.Set( 2 );
	mv.Add( 3 );
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query( 2 ) ) { Fail(); }
	if ( ! mv.Query( 3 ) ) { Fail(); }
	if ( mv.Query( 1 ) ) { Fail(); }  // should be gone, replaced by Set()
	if ( mv.Query( 0 ) ) { Fail(); }  // likewise

	// Set 2, Set 3 (latter should replace former).
	mv.Clear();
	mv.Set( 2 );
	mv.Set( 3 );
	if ( mv.IfEmpty() ) { Fail(); }
	if ( mv.Query( 2 ) ) { Fail(); }   // should've been replaced by 3
	if ( ! mv.Query( 3 ) ) { Fail(); }

	// Test twice.
	mv.Set( 4 );
	mv.Add( 4 );
	mv.Add( 5 );
	mv.Add( 5 );
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query(4) ) { Fail(); }
	if ( ! mv.Query(5) ) { Fail(); }
	if ( mv.Query( 2 ) ) { Fail(); }  // 2 gone
	if ( mv.Query( 3 ) ) { Fail(); }  // 3 gone

	// Test toggle.
	mv.Clear();
	mv.Toggle( 10 );  // add
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query( 10 ) ) { Fail(); }
	mv.Toggle( 10 );  // remove
	if ( ! mv.IfEmpty() ) { Fail(); }
	if ( mv.Query( 10 ) ) { Fail(); }

	// Test toggle adds, not sets.
	mv.Set( 20 );
	mv.Toggle( 21 );  // add
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query( 20 ) ) { Fail(); }
	if ( ! mv.Query( 21 ) ) { Fail(); }
	mv.Toggle( 21 );  // remove
	if ( mv.IfEmpty() ) { Fail(); }
	if ( ! mv.Query( 20 ) ) { Fail(); }  // 20 should remain/unaffected
	if ( mv.Query( 21 ) ) { Fail(); }    // 21 should be toggled off
	return true;

// --
	return true;
}
} // namespace gfx

/*****************************************************************************
 * main.
 *****************************************************************************/
int
main( int argc, char** argv )
{
	GFX_INIT( argv[0] );
	int res = 1;
	if ( MultivarTest() )
	{
		cerr << "Test PASSED. \n";
		res = 0;
	}
	else
	{
		cerr << "Test FAILED! \n";
		res = 1;
	}
	GFX_CLEANUP();
	exit( res );
}
