/*
 * Test emp.research_weights_view
 */
BEGIN;
	/* Remove foreign keys from the empire research table */
	ALTER TABLE emp.technologies
		DROP CONSTRAINT fk_emptech_empire ,
		DROP CONSTRAINT fk_emptech_technology;

	/* Insert a few records */
	DELETE FROM emp.technologies;
	INSERT INTO emp.technologies (
			empire_id , technology_name_id ,
			emptech_state , emptech_points , emptech_priority
		) VALUES
			( 1 , 1 , 'RESEARCH' , 0 , 0 ) ,
			( 1 , 2 , 'RESEARCH' , 0 , 1 ) ,
			( 1 , 3 , 'RESEARCH' , 0 , 2 ) ,
			( 1 , 4 , 'RESEARCH' , 0 , 3 ) ,
			( 1 , 5 , 'RESEARCH' , 0 , 4 ) ,
			( 1 , 6 , 'PENDING' , NULL , NULL ) ,
			( 1 , 7 , 'KNOWN' , NULL , NULL );

	/* Set the constant */
	SELECT sys.uoc_constant( 'game.research.weightBase' , '(test)' , 'Test' , 10.0 );

	/***** TESTS BEGIN HERE *****/
	SELECT plan( 2 );

	SELECT diag_test_name( 'emp.research_weights_view - Rows present' );
	SELECT is( COUNT(*)::INT , 5 )
		FROM emp.research_weights_view;

	SELECT diag_test_name( 'emp.research_weights_view - weight = game.research.weightBase ^ priority' );
	SELECT is_empty( $$
		SELECT * FROM emp.research_weights_view
			WHERE emptech_weight IS NULL
				OR emptech_weight <> POW( 10 , technology_name_id - 1 )
	$$ );

	SELECT * FROM finish( );
ROLLBACK;
