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/040-empire/020-planet-resources-view.sql
Emmanuel BENOîT 597429fadf In-game resources views
* Added session records to carry resource information over to the
clients

* Added SQL support code for the various views

* Added interface and implementation of the resource information access
component

* Hooked resources information queries into both the empire and planet
management component

* Added resources display to planet and overview pages
2012-02-04 10:43:12 +01:00

56 lines
No EOL
1.6 KiB
PL/PgSQL

/*
* Tests for emp.planet_resources_view
*/
BEGIN;
/*
* Create two empires, one with 2 planets, the other without. Add 2 planet
* resources records.
*
* Disable all foreign keys to avoid a lot of work.
*/
ALTER TABLE emp.planets
DROP CONSTRAINT fk_eplanets_empire ,
DROP CONSTRAINT fk_eplanets_planet;
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 , 1 , 2 ) , ( 1 , 2 , 3 , 4 ) ,
( 2 , 1 , 3 , 4 ) , ( 2 , 2 , 5 , 6 ) ,
( 3 , 1 , 0.1 / 720 , 0.4 / 720 ) ,
( 3 , 2 , 0.9 / 720, 0.9 / 720 );
INSERT INTO emp.planets( empire_id , planet_id )
VALUES ( 1 , 1 ) , ( 1 , 2 ) , ( 2 , 3 );
/***** TESTS BEGIN HERE *****/
SELECT plan( 3 );
SELECT diag_test_name( 'emp.planet_resources_view - Sums' );
SELECT set_eq(
$$ SELECT * FROM emp.planet_resources_view WHERE empire_id = 1 $$ ,
$$ VALUES ( 1 , 1 , 4 * 720 , 6 * 720 ) , ( 1 , 2 , 8 * 720 , 10 * 720 ) $$
);
SELECT diag_test_name( 'emp.planet_resources_view - Incomes are rounded down' );
SELECT set_eq(
$$ SELECT resource_name_id , planets_income
FROM emp.planet_resources_view
WHERE empire_id = 2 $$ ,
$$ VALUES ( 1 , 0 ) , ( 2 , 0 ) $$
);
SELECT diag_test_name( 'emp.planet_resources_view - Upkeeps are rounded up' );
SELECT set_eq(
$$ SELECT resource_name_id , planets_upkeep
FROM emp.planet_resources_view
WHERE empire_id = 2 $$ ,
$$ VALUES ( 1 , 1 ) , ( 2 , 1 ) $$
);
SELECT * FROM finish( );
ROLLBACK;