This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/040-functions/145-resource-providers/080-verse-mining-get-input.sql
Emmanuel BENOîT bf6bea5a79 Extracted quantities update as soon as possible
* The quantities of resources extracted from mines will now be updated
as soon as they have a reason to. This includes planet assignment,
abandonment, ownership changes, and updates to mining priorities.

* The mining update will now remove the current resource income from the
providers, and only then re-compute all extracted quantities. This is
more logical and corresponds to the way the other game updates work.

* Fixed bug in extraction computation where the size of the planet's
happy population was used instead of the happy/total ratio when
adjusting the mining production for riots.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/040-empire.sql
  -> 040-functions/145-resource-providers.sql
  -> 040-functions/147-empire-mining.sql
  -> 050-updates/120-planet-mining.sql
2012-02-09 10:54:00 +01:00

88 lines
No EOL
3.7 KiB
PL/PgSQL

/*
* 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;