88 lines
3.7 KiB
MySQL
88 lines
3.7 KiB
MySQL
|
/*
|
||
|
* Tests for the verse.mining_get_input() function
|
||
|
*/
|
||
|
BEGIN;
|
||
|
\i utils/common-setup/setup-gu-pmc-get-data-test.sql
|
||
|
|
||
|
SELECT plan( 9 );
|
||
|
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Neutral planet without resource providers -> no rows' );
|
||
|
SELECT is_empty( $$ SELECT * FROM verse.mining_get_input( _get_map_name( 'planet1' ) ) $$ );
|
||
|
|
||
|
CREATE TEMPORARY TABLE test_results
|
||
|
AS SELECT * FROM verse.mining_get_input( _get_map_name( 'planet2' ) );
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Neutral planet with resource providers - Rows included' );
|
||
|
SELECT is( COUNT(*)::INT , 2)
|
||
|
FROM test_results
|
||
|
WHERE planet = _get_map_name ( 'planet2' )
|
||
|
AND difficulty = 0.2 AND empire IS NULL
|
||
|
AND happiness IS NULL AND weight IS NULL
|
||
|
AND total_weight IS NULL;
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Neutral planet with resource providers - No extra rows' );
|
||
|
SELECT is_empty( $$
|
||
|
SELECT * FROM test_results
|
||
|
WHERE NOT ( planet = _get_map_name ( 'planet2' )
|
||
|
AND difficulty = 0.2 AND empire IS NULL
|
||
|
AND happiness IS NULL AND weight IS NULL
|
||
|
AND total_weight IS NULL );
|
||
|
$$ );
|
||
|
DROP TABLE test_results;
|
||
|
|
||
|
CREATE TEMPORARY TABLE test_results
|
||
|
AS SELECT * FROM verse.mining_get_input( _get_map_name( 'planet3' ) );
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Planet using empire settings - Rows included' );
|
||
|
SELECT is( COUNT(*)::INT , 2)
|
||
|
FROM test_results
|
||
|
WHERE planet = _get_map_name ( 'planet3' ) AND difficulty = 0.3
|
||
|
AND empire = _get_emp_name( 'empire1' )
|
||
|
AND happiness IS NOT NULL AND weight = 100
|
||
|
AND total_weight = 200;
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Planet using empire settings - No extra rows' );
|
||
|
SELECT is_empty( $$
|
||
|
SELECT * FROM test_results
|
||
|
WHERE NOT ( planet = _get_map_name ( 'planet3' )
|
||
|
AND difficulty = 0.3
|
||
|
AND empire = _get_emp_name( 'empire1' )
|
||
|
AND happiness IS NOT NULL
|
||
|
AND weight = 100 AND total_weight = 200 );
|
||
|
$$ );
|
||
|
DROP TABLE test_results;
|
||
|
|
||
|
CREATE TEMPORARY TABLE test_results
|
||
|
AS SELECT * FROM verse.mining_get_input( _get_map_name( 'planet4' ) );
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Planet using specific settings - Rows included' );
|
||
|
SELECT is( COUNT(*)::INT , 2)
|
||
|
FROM test_results
|
||
|
WHERE planet = _get_map_name ( 'planet4' ) AND difficulty = 0.4
|
||
|
AND empire = _get_emp_name( 'empire2' )
|
||
|
AND happiness IS NOT NULL AND (
|
||
|
( resource = _get_string( 'resource1' ) AND weight = 10 )
|
||
|
OR ( resource = _get_string( 'resource2' ) AND weight = 1000 ) )
|
||
|
AND total_weight = 1010;
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Planet using specific settings - No extra rows' );
|
||
|
SELECT is_empty( $$
|
||
|
SELECT * FROM test_results
|
||
|
WHERE NOT ( planet = _get_map_name ( 'planet4' )
|
||
|
AND difficulty = 0.4 AND empire = _get_emp_name( 'empire2' )
|
||
|
AND happiness IS NOT NULL AND total_weight = 1010
|
||
|
AND ( ( resource = _get_string( 'resource1' ) AND weight = 10 )
|
||
|
OR ( resource = _get_string( 'resource2' ) AND weight = 1000 ) ) );
|
||
|
$$ );
|
||
|
DROP TABLE test_results;
|
||
|
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Owned planet without resource providers -> no rows' );
|
||
|
SELECT is_empty( $$ SELECT * FROM verse.mining_get_input( _get_map_name( 'planet5' ) ) $$ );
|
||
|
|
||
|
CREATE TEMPORARY TABLE test_results
|
||
|
AS SELECT * FROM verse.mining_get_input( _get_map_name( 'planet6' ) );
|
||
|
SELECT diag_test_name( 'verse.mining_get_input() - Selects planets independently of update state' );
|
||
|
SELECT is( COUNT(*)::INT , 2)
|
||
|
FROM test_results
|
||
|
WHERE planet = _get_map_name ( 'planet6' ) AND difficulty = 0.6
|
||
|
AND empire = _get_emp_name( 'empire4' )
|
||
|
AND happiness IS NOT NULL AND weight = 100
|
||
|
AND total_weight = 200;
|
||
|
DROP TABLE test_results;
|
||
|
|
||
|
SELECT * FROM finish( );
|
||
|
ROLLBACK;
|