/*
* Test the emp.create_empire() function
*/
BEGIN;
/* We need a pair of natural resources, a basic resource, a planet
* and an empire name.
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
\i utils/universe.sql
SELECT _create_natural_resources( 2 , 'natRes' );
SELECT _create_resources( 1 , 'basicRes' );
SELECT _create_raw_planets( 1 , 'testPlanet' );
SELECT _create_emp_names( 1 , 'testEmp' );
/***** TESTS BEGIN HERE *****/
SELECT plan( 8 );
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
_get_map_name( 'testPlanet1' ) ,
200.0 );
SELECT diag_test_name( 'emp.create_empire() - Empire exists' );
SELECT is( COUNT(*)::INT , 1 ) FROM emp.empires
WHERE name_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Empire cash' );
SELECT is( cash , 200.0::REAL ) FROM emp.empires
SELECT diag_test_name( 'emp.create_empire() - Empire debt' );
SELECT is( debt , 0.0::REAL ) FROM emp.empires
SELECT diag_test_name( 'emp.create_empire() - Empire mining settings include all natural resources' );
SELECT is( COUNT(*)::INT , 2 )
FROM defs.natural_resources
INNER JOIN emp.mining_settings
USING ( resource_name_id )
WHERE empire_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Empire mining settings do not include basic resources' );
FROM defs.resources
SELECT diag_test_name( 'emp.create_empire() - Empire mining settings are all set to 2' );
SELECT is( COUNT( * )::INT , 0 )
FROM emp.mining_settings
WHERE empire_id = _get_emp_name( 'testEmp1' )
AND empmset_weight <> 2;
SELECT diag_test_name( 'emp.create_empire() - Empire resources have been initialised' );
SELECT is( COUNT(*)::INT , 3 )
FROM emp.resources
SELECT diag_test_name( 'emp.create_empire() - Empire update records' );
SELECT is( _eur.quantity , _utv.quantity)
FROM (
SELECT COUNT(*) AS quantity FROM emp.updates
) AS _eur , (
SELECT COUNT(*) AS quantity
FROM unnest( enum_range( NULL::update_type ) ) AS _row
WHERE _row::TEXT LIKE 'EMPIRE_%'
) AS _utv;
SELECT * FROM finish( );
ROLLBACK;