/*
  testvv.c: test program for VV class
*/


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>


#include "vector2.h"
#include "vv.h"
#include "testsupport.h"


int main( void )
{
	VV origin      = new_VV( 0, 0 );      // VV in VV
	Vector2 a      = new_VV( 10, 0 );     // VV in Vector2
	Vector2 b      = new_Vector2( 0, 10 );// Vector2 in Vector2

	// d = origin->magnitude, using OM0 (object-method-call) helper
	double d     = OM0(origin,magnitude);
	DOUBLE_SAME( d, 0 );

	// d = origin->distance_to(a),
	// using OM1 (object-method-params-call) helper
	d     = OM1(origin,distance_to,a);
	DOUBLE_SAME( d, 10 );

	DOUBLE_SAME( OM0(origin,magnitude), 0 );
	DOUBLE_SAME( OM1(origin,distance_to,origin), 0 );

	DOUBLE_SAME( origin->magnitude(origin), 0 );
	DOUBLE_SAME( origin->distance_to(origin,origin), 0 );
	DOUBLE_SAME( origin->distance_to(origin,a), 10 );
	DOUBLE_SAME( origin->distance_to(origin,b), 10 );
	DOUBLE_SAME( a->magnitude(a), 10 );
	DOUBLE_SAME( a->distance_to(a,origin), 10 );
	DOUBLE_SAME( a->distance_to(a,a), 0 );
	DOUBLE_SAME( a->distance_to(a,b), 14.1421 );
	DOUBLE_SAME( b->magnitude(b), 10 );
	DOUBLE_SAME( b->distance_to(b,origin), 10 );
	DOUBLE_SAME( b->distance_to(b,a), 14.1421 );
	DOUBLE_SAME( b->distance_to(b,b), 0 );

	OM0(a,normalize);
	DOUBLE_SAME( a->magnitude(a), 1.0 );

	OM1(a,scale,5);
	DOUBLE_SAME( a->magnitude(a), 5.0 );

	OM1(a,add,b);
	DOUBLE_SAME( a->magnitude(a), 11.1803 );

	STR_SAME( a->isa, "VV" );

	OM0( b, dispose );
	OM0( a, dispose );
	OM0( origin, dispose );
	exit(0);
	return 0;
}
