Emmanuel BENOîT
74b6f2ab09
* Added various views and helper functions used by the mining computation but which may be re-used in other parts. * Added mining computation update type and associated update function * New constants: game.resources.weightBase (the value used to compute weights from mining settings) and game.resources.extraction (the quantity extracted in a day from a full provider at difficulty 0)
58 lines
No EOL
1.7 KiB
PL/PgSQL
58 lines
No EOL
1.7 KiB
PL/PgSQL
/*
|
|
* Test the sys.process_planet_mining_updates() function
|
|
*/
|
|
BEGIN;
|
|
/*
|
|
* Create a fake planet resource record which will be updated by the
|
|
* function (dropping the foreign key is therefore needed).
|
|
*/
|
|
ALTER TABLE verse.planet_resources
|
|
DROP CONSTRAINT fk_pres_planet ,
|
|
DROP CONSTRAINT fk_pres_resource;
|
|
|
|
INSERT INTO verse.planet_resources(
|
|
planet_id , resource_name_id , pres_income , pres_upkeep
|
|
) VALUES (
|
|
1 , 1 , 42 , 0
|
|
);
|
|
|
|
/*
|
|
* Create a table which contains the values which will be returned by
|
|
* the fake sys.gu_pmc_get_data( ).
|
|
*/
|
|
CREATE TABLE _fake_update_data OF sys.gu_pmc_data_type;
|
|
INSERT INTO _fake_update_data VALUES (
|
|
1 , 1 , 1000.0 , 1000.0 , 0.5 , NULL , NULL , NULL , NULL ) ,
|
|
( 2 , 1 , 1000.0 , 1000.0 , 0.5 , 1 , 0.5 , 1.0 , 1.0 );
|
|
CREATE OR REPLACE FUNCTION sys.gu_pmc_get_data( _tick BIGINT )
|
|
RETURNS SETOF sys.gu_pmc_data_type
|
|
AS $$
|
|
SELECT * FROM _fake_update_data;
|
|
$$ LANGUAGE SQL;
|
|
|
|
/*
|
|
* Replace sys.gu_pmc_update_resource() so it deletes records from the
|
|
* table.
|
|
*/
|
|
CREATE OR REPLACE FUNCTION sys.gu_pmc_update_resource( _input sys.gu_pmc_data_type )
|
|
RETURNS VOID
|
|
AS $$
|
|
DELETE FROM _fake_update_data WHERE planet = $1.planet AND resource = $1.resource;
|
|
$$ LANGUAGE SQL;
|
|
|
|
|
|
/***** TESTS BEGIN HERE *****/
|
|
SELECT no_plan( );
|
|
|
|
SELECT sys.process_planet_mining_updates( 0 );
|
|
|
|
SELECT diag_test_name( 'sys.process_planet_mining_updates() - Neutral planets updated' );
|
|
SELECT is( pres_income , 0::DOUBLE PRECISION ) FROM verse.planet_resources;
|
|
|
|
SELECT diag_test_name( 'sys.process_planet_mining_updates() - Owned planets updated' );
|
|
SELECT is_empty(
|
|
$$ SELECT * FROM _fake_update_data WHERE planet = 2 $$
|
|
);
|
|
|
|
SELECT * FROM finish( );
|
|
ROLLBACK; |