Emmanuel BENOîT
bf6bea5a79
* 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
118 lines
3.7 KiB
PL/PgSQL
118 lines
3.7 KiB
PL/PgSQL
/*
|
|
* Test the emp.mset_update_apply() function
|
|
*/
|
|
BEGIN;
|
|
/*
|
|
* Create a pair of strings
|
|
*/
|
|
INSERT INTO defs.strings (name) VALUES ( 'a' ) , ( 'b' );
|
|
|
|
/*
|
|
* Remove foreign keys from the empire mining settings table, insert some
|
|
* data into it.
|
|
*/
|
|
ALTER TABLE emp.mining_settings
|
|
DROP CONSTRAINT fk_empmset_empire ,
|
|
DROP CONSTRAINT fk_empmset_resource;
|
|
INSERT INTO emp.mining_settings ( empire_id , resource_name_id )
|
|
SELECT 1 , id
|
|
FROM defs.strings
|
|
WHERE name IN ( 'a' , 'b' );
|
|
|
|
/* Create the temporary table */
|
|
CREATE TEMPORARY TABLE mset_update(
|
|
empire_id INT ,
|
|
resource_name TEXT ,
|
|
empmset_weight INT
|
|
) ON COMMIT DROP;
|
|
INSERT INTO mset_update VALUES ( 1 , 'a' , 0 ) , ( 1 , 'b' , 4 );
|
|
|
|
/***** TESTS BEGIN HERE *****/
|
|
SELECT plan( 8 );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying valid empire update' );
|
|
SELECT ok( emp.mset_update_apply( ) );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Empire update results' );
|
|
SELECT set_eq(
|
|
$$ SELECT name , empmset_weight
|
|
FROM emp.mining_settings
|
|
INNER JOIN defs.strings
|
|
ON resource_name_id = id $$ ,
|
|
$$ VALUES ( 'a' , 0 ) , ( 'b' , 4 ) $$
|
|
);
|
|
|
|
/* Reset temporary table and settings */
|
|
DELETE FROM mset_update;
|
|
DELETE FROM emp.mining_settings;
|
|
INSERT INTO emp.mining_settings ( empire_id , resource_name_id )
|
|
SELECT 1 , id
|
|
FROM defs.strings
|
|
WHERE name IN ( 'a' , 'b' );
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 'a' , -1 ) , ( 1 , 'b' , 4 );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying invalid empire update' );
|
|
SELECT ok( NOT emp.mset_update_apply( ) );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Invalid empire update results' );
|
|
SELECT set_eq(
|
|
$$ SELECT name , empmset_weight
|
|
FROM emp.mining_settings
|
|
INNER JOIN defs.strings
|
|
ON resource_name_id = id $$ ,
|
|
$$ VALUES ( 'a' , 2 ) , ( 'b' , 2 ) $$
|
|
);
|
|
|
|
|
|
/* Re-create the temporary table to store planet mining settings, remove
|
|
* constraints from the planet mining settings table, insert data into
|
|
* both.
|
|
*/
|
|
ALTER TABLE emp.planet_mining_settings
|
|
DROP CONSTRAINT fk_emppmset_empire ,
|
|
DROP CONSTRAINT fk_emppmset_resource;
|
|
INSERT INTO emp.planet_mining_settings ( empire_id , planet_id , resource_name_id )
|
|
SELECT 1 , 1 , id
|
|
FROM defs.strings
|
|
WHERE name IN ( 'a' , 'b' );
|
|
|
|
DROP TABLE mset_update;
|
|
CREATE TEMPORARY TABLE mset_update(
|
|
empire_id INT ,
|
|
planet_id INT ,
|
|
resource_name TEXT ,
|
|
empmset_weight INT
|
|
) ON COMMIT DROP;
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , 'a' , 0 ) , ( 1 , 1 , 'b' , 4 );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying valid planet update' );
|
|
SELECT ok( emp.mset_update_apply( ) );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Planet update results' );
|
|
SELECT set_eq(
|
|
$$ SELECT name , emppmset_weight
|
|
FROM emp.planet_mining_settings
|
|
INNER JOIN defs.strings
|
|
ON resource_name_id = id $$ ,
|
|
$$ VALUES ( 'a' , 0 ) , ( 'b' , 4 ) $$
|
|
);
|
|
|
|
/* Reset temporary table and settings */
|
|
DELETE FROM mset_update;
|
|
DELETE FROM emp.planet_mining_settings;
|
|
INSERT INTO emp.planet_mining_settings ( empire_id , planet_id , resource_name_id )
|
|
SELECT 1 , 1 , id
|
|
FROM defs.strings
|
|
WHERE name IN ( 'a' , 'b' );
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , 'a' , -1 ) , ( 1 , 1 , 'b' , 4 );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying invalid planet update' );
|
|
SELECT ok( NOT emp.mset_update_apply( ) );
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Invalid planet update results' );
|
|
SELECT set_eq(
|
|
$$ SELECT name , emppmset_weight
|
|
FROM emp.planet_mining_settings
|
|
INNER JOIN defs.strings
|
|
ON resource_name_id = id $$ ,
|
|
$$ VALUES ( 'a' , 2 ) , ( 'b' , 2 ) $$
|
|
);
|
|
|
|
SELECT * FROM finish( );
|
|
ROLLBACK;
|