Moved empire research SQL to separate file
* Empire research & technology SQL code was getting dense, so it was moved to a separate file.
This commit is contained in:
parent
1dcde71dff
commit
c9d8a077bd
16 changed files with 416 additions and 407 deletions
legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.technology_implement()
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
\i utils/universe.sql
|
||||
|
||||
/*
|
||||
* Create empires
|
||||
*/
|
||||
SELECT _create_emp_names( 4 , 'emp' );
|
||||
INSERT INTO emp.empires ( name_id , cash )
|
||||
SELECT id , 200 FROM naming.empire_names;
|
||||
|
||||
/*
|
||||
* We also need 3 technologies (tech1, tech2 and tech3), and some
|
||||
* dependencies between them: tech3 -> {tech2, tech1}). Disabling
|
||||
* unused fields in defs.technologies makes things easier.
|
||||
*/
|
||||
ALTER TABLE defs.technologies
|
||||
ALTER technology_category_id DROP NOT NULL ,
|
||||
ALTER technology_discovery_id DROP NOT NULL ,
|
||||
ALTER technology_description_id DROP NOT NULL ,
|
||||
ALTER technology_points DROP NOT NULL;
|
||||
SELECT _create_test_strings( 3 , 'tech' );
|
||||
INSERT INTO defs.technologies ( technology_name_id , technology_price )
|
||||
VALUES ( _get_string( 'tech1' ) , 200 ) ,
|
||||
( _get_string( 'tech2' ) , 200 ) ,
|
||||
( _get_string( 'tech3' ) , 300 );
|
||||
INSERT INTO defs.technology_dependencies(
|
||||
technology_name_id , technology_name_id_depends
|
||||
) VALUES ( _get_string( 'tech3' ) , _get_string( 'tech1' ) ) ,
|
||||
( _get_string( 'tech3' ) , _get_string( 'tech2' ) );
|
||||
|
||||
/* Empire "emp1" has only in-progress research. */
|
||||
INSERT INTO emp.technologies_v2 ( empire_id , technology_name_id )
|
||||
VALUES( _get_emp_name( 'emp1' ) , _get_string( 'tech1' ) );
|
||||
|
||||
/* Empire "emp2" has a pending technology. */
|
||||
INSERT INTO emp.technologies_v2 ( empire_id , technology_name_id , emptech_state , emptech_points , emptech_priority )
|
||||
VALUES( _get_emp_name( 'emp2' ) , _get_string( 'tech1' ) , 'PENDING' , NULL , NULL );
|
||||
|
||||
/* Empire "emp3" has implemented 'tech1' and has 'tech2' as pending. */
|
||||
INSERT INTO emp.technologies_v2 ( empire_id , technology_name_id , emptech_state , emptech_points , emptech_priority )
|
||||
VALUES( _get_emp_name( 'emp3' ) , _get_string( 'tech1' ) , 'KNOWN' , NULL , NULL ) ,
|
||||
( _get_emp_name( 'emp3' ) , _get_string( 'tech2' ) , 'PENDING' , NULL , NULL );
|
||||
|
||||
/* Empire "emp4" has implemented 'tech1' and 'tech2' and has 'tech3' as pending. */
|
||||
INSERT INTO emp.technologies_v2 ( empire_id , technology_name_id , emptech_state , emptech_points , emptech_priority )
|
||||
VALUES( _get_emp_name( 'emp4' ) , _get_string( 'tech1' ) , 'KNOWN' , NULL , NULL ) ,
|
||||
( _get_emp_name( 'emp4' ) , _get_string( 'tech2' ) , 'KNOWN' , NULL , NULL ) ,
|
||||
( _get_emp_name( 'emp4' ) , _get_string( 'tech3' ) , 'PENDING' , NULL , NULL );
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 10 );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on in-progress research' );
|
||||
SELECT ok( NOT emp.technology_implement( _get_emp_name( 'emp1' ) , 'tech1' ) );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on unknown technology' );
|
||||
SELECT ok( NOT emp.technology_implement( _get_emp_name( 'emp1' ) , 'tech2' ) );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on implemented technology' );
|
||||
SELECT ok( NOT emp.technology_implement( _get_emp_name( 'emp3' ) , 'tech1' ) );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - No new research - Return value' );
|
||||
SELECT ok( emp.technology_implement( _get_emp_name( 'emp2' ) , 'tech1' ) );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - No new research - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT technology_name_id , emptech_state::TEXT
|
||||
FROM emp.technologies_v2
|
||||
WHERE empire_id = _get_emp_name( 'emp2' )
|
||||
$$ , $$ VALUES(
|
||||
_get_string( 'tech1' ) , 'KNOWN'
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - No new research - Empire cash' );
|
||||
SELECT is( cash , 0.0::REAL ) FROM emp.empires
|
||||
WHERE name_id = _get_emp_name( 'emp2' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - New research - Return value' );
|
||||
SELECT ok( emp.technology_implement( _get_emp_name( 'emp3' ) , 'tech2' ) );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - New research - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT technology_name_id , emptech_state::TEXT
|
||||
FROM emp.technologies_v2
|
||||
WHERE empire_id = _get_emp_name( 'emp3' )
|
||||
$$ , $$ VALUES(
|
||||
_get_string( 'tech1' ) , 'KNOWN'
|
||||
) , (
|
||||
_get_string( 'tech2' ) , 'KNOWN'
|
||||
) , (
|
||||
_get_string( 'tech3' ) , 'RESEARCH'
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology - New research - Empire cash' );
|
||||
SELECT is( cash , 0.0::REAL ) FROM emp.empires
|
||||
WHERE name_id = _get_emp_name( 'emp3' );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_implement() - Call on pending technology when empire cash is too low' );
|
||||
SELECT ok( NOT emp.technology_implement( _get_emp_name( 'emp4' ) , 'tech3' ) );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.technology_make_identifier()
|
||||
*/
|
||||
BEGIN;
|
||||
SELECT no_plan( );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_make_identifier() - Identifier of visible technologies' );
|
||||
SELECT is( emp.technology_make_identifier( 1 , 'test-string' , TRUE ) , 'test-string' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_make_identifier() - Identifier of unknown technologies - 32 characters' );
|
||||
SELECT is( length( emp.technology_make_identifier( 1 , 'test-string' , FALSE ) ) , 32 );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_make_identifier() - Identifier of unknown technologies - Contains hex value' );
|
||||
SELECT ok( emp.technology_make_identifier( 1 , 'test-string' , FALSE ) !~ '[^a-f0-9]' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.resprio_update_start()
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
|
||||
/* Create two empires */
|
||||
SELECT _create_emp_names( 2 , 'emp' );
|
||||
INSERT INTO emp.empires ( name_id , cash )
|
||||
SELECT id , 200.0 FROM naming.empire_names;
|
||||
|
||||
/* Create 3 technologies after disabling unused fields */
|
||||
ALTER TABLE defs.technologies
|
||||
ALTER technology_category_id DROP NOT NULL ,
|
||||
ALTER technology_discovery_id DROP NOT NULL ,
|
||||
ALTER technology_description_id DROP NOT NULL ,
|
||||
ALTER technology_price DROP NOT NULL ,
|
||||
ALTER technology_points DROP NOT NULL;
|
||||
SELECT _create_test_strings( 3 , 'tech' );
|
||||
INSERT INTO defs.technologies ( technology_name_id )
|
||||
VALUES ( _get_string( 'tech1' ) ) ,
|
||||
( _get_string( 'tech2' ) ) ,
|
||||
( _get_string( 'tech3' ) );
|
||||
|
||||
/* Replace identifier function with something easier to check */
|
||||
CREATE OR REPLACE FUNCTION emp.technology_make_identifier(
|
||||
_empire INT , _technology TEXT , _visible BOOLEAN )
|
||||
RETURNS TEXT
|
||||
LANGUAGE SQL
|
||||
STRICT IMMUTABLE
|
||||
SECURITY DEFINER
|
||||
AS $technology_make_identifier$
|
||||
SELECT $1::TEXT || ',' || $2 || ',' || $3::TEXT;
|
||||
$technology_make_identifier$;
|
||||
|
||||
/* Replace the visibility view with plain SELECT's from a table.
|
||||
*/
|
||||
CREATE TABLE _fake_visibility(
|
||||
empire_id INT ,
|
||||
technology_name_id INT ,
|
||||
emptech_visible BOOLEAN
|
||||
);
|
||||
CREATE OR REPLACE VIEW emp.technology_visibility_view
|
||||
AS SELECT * FROM _fake_visibility;
|
||||
|
||||
/* Insert empire state and data for fake views */
|
||||
INSERT INTO emp.technologies_v2 (
|
||||
empire_id , technology_name_id ,
|
||||
emptech_state , emptech_points , emptech_priority
|
||||
) VALUES (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) ,
|
||||
'KNOWN' , NULL , NULL
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech2' ) ,
|
||||
'RESEARCH' , 123 , 0
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech3' ) ,
|
||||
'RESEARCH' , 123 , 1
|
||||
);
|
||||
INSERT INTO _fake_visibility VALUES(
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , TRUE
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech2' ) , TRUE
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech3' ) , FALSE
|
||||
);
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 9 );
|
||||
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Invalid empire - Return value' );
|
||||
SELECT ok( NOT emp.resprio_update_start( _get_bad_emp_name() ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Invalid empire - Temporary table exists' );
|
||||
SELECT has_table( 'rprio_update' );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Invalid empire - Temporary table is empty' );
|
||||
SELECT is_empty( $$ SELECT * FROM rprio_update $$ );
|
||||
DROP TABLE IF EXISTS rprio_update;
|
||||
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with no research - Return value' );
|
||||
SELECT ok( NOT emp.resprio_update_start( _get_emp_name( 'emp2' ) ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with no research - Temporary table exists' );
|
||||
SELECT has_table( 'rprio_update' );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with no research - Temporary table is empty' );
|
||||
SELECT is_empty( $$ SELECT * FROM rprio_update $$ );
|
||||
DROP TABLE IF EXISTS rprio_update;
|
||||
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with in-progress research - Return value' );
|
||||
SELECT ok( emp.resprio_update_start( _get_emp_name( 'emp1' ) ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with in-progress research - Temporary table exists' );
|
||||
SELECT has_table( 'rprio_update' );
|
||||
SELECT diag_test_name( 'emp.resprio_update_start() - Empire with in-progress research - Temporary table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT _empire_id , _technology_name_id , _emptech_id , _emptech_priority
|
||||
FROM rprio_update
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech2' ) , _get_emp_name( 'emp1' ) || ',tech2,true' , 0
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech3' ) , _get_emp_name( 'emp1' ) || ',tech3,false' , 1
|
||||
) $$ );
|
||||
DROP TABLE IF EXISTS rprio_update;
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.resprio_update_set( )
|
||||
*/
|
||||
BEGIN;
|
||||
/* Create a fake temporary table and insert some values */
|
||||
CREATE TEMPORARY TABLE rprio_update(
|
||||
_empire_id INT ,
|
||||
_technology_name_id INT ,
|
||||
_emptech_id TEXT ,
|
||||
_emptech_priority INT
|
||||
) ON COMMIT DROP;
|
||||
INSERT INTO rprio_update
|
||||
VALUES ( 1 , 1 , 'test' , 2 );
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 4 );
|
||||
|
||||
SELECT diag_test_name( 'emp.resprio_update_set() - Using a bad identifier - Return value' );
|
||||
SELECT ok( NOT emp.resprio_update_set( 'bad identifier' , 3 ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_set() - Using a bad identifier - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT * FROM rprio_update
|
||||
$$ , $$ VALUES(
|
||||
1 , 1 , 'test' , 2
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'emp.resprio_update_set() - Using a valid identifier - Return value' );
|
||||
SELECT ok( emp.resprio_update_set( 'test' , 3 ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_set() - Using a bad identifier - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT * FROM rprio_update
|
||||
$$ , $$ VALUES(
|
||||
1 , 1 , 'test' , 3
|
||||
) $$ );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.resprio_update_apply()
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
|
||||
/* Create a pair of empires, a technology, and some empire
|
||||
* research & technology records.
|
||||
*/
|
||||
SELECT _create_emp_names( 2 , 'emp' );
|
||||
INSERT INTO emp.empires ( name_id , cash )
|
||||
SELECT id , 200.0 FROM naming.empire_names;
|
||||
|
||||
ALTER TABLE defs.technologies
|
||||
ALTER technology_category_id DROP NOT NULL ,
|
||||
ALTER technology_discovery_id DROP NOT NULL ,
|
||||
ALTER technology_description_id DROP NOT NULL ,
|
||||
ALTER technology_price DROP NOT NULL ,
|
||||
ALTER technology_points DROP NOT NULL;
|
||||
SELECT _create_test_strings( 1 , 'tech' );
|
||||
INSERT INTO defs.technologies ( technology_name_id )
|
||||
VALUES ( _get_string( 'tech1' ) );
|
||||
|
||||
INSERT INTO emp.technologies_v2(
|
||||
empire_id , technology_name_id ,
|
||||
emptech_state , emptech_points , emptech_priority
|
||||
) VALUES (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) ,
|
||||
'RESEARCH' , 12 , 2
|
||||
) , (
|
||||
_get_emp_name( 'emp2' ) , _get_string( 'tech1' ) ,
|
||||
'RESEARCH' , 12 , 2
|
||||
);
|
||||
|
||||
/* Create a fake temporary table */
|
||||
CREATE TEMPORARY TABLE rprio_update(
|
||||
_empire_id INT ,
|
||||
_technology_name_id INT ,
|
||||
_emptech_id TEXT ,
|
||||
_emptech_priority INT
|
||||
) ON COMMIT DROP;
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 4 );
|
||||
|
||||
INSERT INTO rprio_update
|
||||
VALUES ( _get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , 'ignored' , 1 );
|
||||
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying a valid update - Return value' );
|
||||
SELECT ok( emp.resprio_update_apply( ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying a valid update - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT empire_id , emptech_priority
|
||||
FROM emp.technologies_v2
|
||||
WHERE technology_name_id = _get_string( 'tech1' );
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp1' ) , 1
|
||||
) , (
|
||||
_get_emp_name( 'emp2' ) , 2
|
||||
) $$ );
|
||||
DELETE FROM rprio_update;
|
||||
UPDATE emp.technologies_v2
|
||||
SET emptech_priority = 2
|
||||
WHERE technology_name_id = _get_string( 'tech1' );
|
||||
|
||||
INSERT INTO rprio_update
|
||||
VALUES ( _get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , 'ignored' , 15 );
|
||||
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying an invalid update - Return value' );
|
||||
SELECT ok( NOT emp.resprio_update_apply( ) );
|
||||
SELECT diag_test_name( 'emp.resprio_update_apply() - Applying an invalid update - Table contents' );
|
||||
SELECT set_eq( $$
|
||||
SELECT empire_id , emptech_priority
|
||||
FROM emp.technologies_v2
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp1' ) , 2
|
||||
) , (
|
||||
_get_emp_name( 'emp2' ) , 2
|
||||
) $$ );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.technology_visibility_view
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
|
||||
/* Create a single empire */
|
||||
SELECT _create_emp_names( 1 , 'emp' );
|
||||
INSERT INTO emp.empires ( name_id , cash )
|
||||
VALUES ( _get_emp_name( 'emp1' ) , 200 );
|
||||
|
||||
/*
|
||||
* Set visibility thresholds to either 50% or 100 points.
|
||||
*/
|
||||
SELECT sys.uoc_constant( 'game.research.visibility.points' , '(test)' , 'Test' , 100.0 );
|
||||
SELECT sys.uoc_constant( 'game.research.visibility.ratio' , '(test)' , 'Test' , 0.5 );
|
||||
|
||||
/* Create 6 technology definitions that will be used to test various
|
||||
* states: pending, known, 4 variants of research in progress (points
|
||||
* and ratio below thresholds, points below threshold, ratio below
|
||||
* threshold, both points and ratio above thresholds).
|
||||
*
|
||||
* Disable all unused fields from the definition table.
|
||||
*/
|
||||
ALTER TABLE defs.technologies
|
||||
ALTER technology_category_id DROP NOT NULL ,
|
||||
ALTER technology_discovery_id DROP NOT NULL ,
|
||||
ALTER technology_description_id DROP NOT NULL ,
|
||||
ALTER technology_price DROP NOT NULL;
|
||||
SELECT _create_test_strings( 6 , 'tech' );
|
||||
INSERT INTO defs.technologies( technology_name_id , technology_points )
|
||||
VALUES ( _get_string( 'tech1' ) , 100 ) ,
|
||||
( _get_string( 'tech2' ) , 100 ) ,
|
||||
( _get_string( 'tech3' ) , 100 ) ,
|
||||
( _get_string( 'tech4' ) , 100 ) ,
|
||||
( _get_string( 'tech5' ) , 1000 ) ,
|
||||
( _get_string( 'tech6' ) , 1000 );
|
||||
|
||||
/* Insert empire state */
|
||||
INSERT INTO emp.technologies_v2 (
|
||||
empire_id , technology_name_id ,
|
||||
emptech_state , emptech_points , emptech_priority
|
||||
) VALUES (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) ,
|
||||
'KNOWN' , NULL , NULL
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech2' ) ,
|
||||
'PENDING' , NULL , NULL
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech3' ) ,
|
||||
'RESEARCH' , 10.0 , 2
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech4' ) ,
|
||||
'RESEARCH' , 51.0 , 2
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech5' ) ,
|
||||
'RESEARCH' , 101.0 , 2
|
||||
) , (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech6' ) ,
|
||||
'RESEARCH' , 501.0 , 2
|
||||
);
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 7 );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - All technologies are listed' );
|
||||
SELECT is( COUNT( * )::INT , 6 )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - Known technologies are visible' );
|
||||
SELECT ok( emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech1' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - Pending technologies are visible' );
|
||||
SELECT ok( emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech2' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - In-progress technologies with both points and ratios below thresholds are not visible' );
|
||||
SELECT ok( NOT emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech3' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - In-progress technologies with points below threshold are visible' );
|
||||
SELECT ok( emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech4' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - In-progress technologies with ratio below threshold are visible' );
|
||||
SELECT ok( emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech5' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
SELECT diag_test_name( 'emp.technology_visibility_view - In-progress technologies with both points and ratios above threshold are visible' );
|
||||
SELECT ok( emptech_visible )
|
||||
FROM emp.technology_visibility_view
|
||||
WHERE technology_name_id = _get_string( 'tech6' )
|
||||
AND empire_id = _get_emp_name( 'emp1' );
|
||||
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* Unit tests for emp.technologies_v2_view
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
|
||||
/* Create three empires (easier to use as keys) */
|
||||
SELECT _create_emp_names( 3 , 'emp' );
|
||||
INSERT INTO emp.empires ( name_id , cash )
|
||||
SELECT id , 200.0 FROM naming.empire_names;
|
||||
|
||||
/* Create a technology after disabling unused fields */
|
||||
ALTER TABLE defs.technologies
|
||||
ALTER technology_discovery_id DROP NOT NULL;
|
||||
SELECT _create_test_strings( 1 , 'tech' );
|
||||
SELECT _create_test_strings( 1 , 'techCategory' );
|
||||
SELECT _create_test_strings( 1 , 'techDescription' );
|
||||
INSERT INTO defs.technologies (
|
||||
technology_name_id , technology_category_id , technology_description_id ,
|
||||
technology_price , technology_points
|
||||
) VALUES (
|
||||
_get_string( 'tech1' ) , _get_string( 'techCategory1' ) , _get_string( 'techDescription1' ) ,
|
||||
123 , 456
|
||||
);
|
||||
|
||||
/* Replace identifier function with something easier to check */
|
||||
CREATE OR REPLACE FUNCTION emp.technology_make_identifier(
|
||||
_empire INT , _technology TEXT , _visible BOOLEAN )
|
||||
RETURNS TEXT
|
||||
LANGUAGE SQL
|
||||
STRICT IMMUTABLE
|
||||
SECURITY DEFINER
|
||||
AS $technology_make_identifier$
|
||||
SELECT $1::TEXT || ',' || $2 || ',' || $3::TEXT;
|
||||
$technology_make_identifier$;
|
||||
|
||||
/* Replace both the visibility and dependencies views with plain SELECT's
|
||||
* from tables.
|
||||
*/
|
||||
CREATE TABLE _fake_visibility(
|
||||
empire_id INT ,
|
||||
technology_name_id INT ,
|
||||
emptech_visible BOOLEAN
|
||||
);
|
||||
CREATE OR REPLACE VIEW emp.technology_visibility_view
|
||||
AS SELECT * FROM _fake_visibility;
|
||||
CREATE TABLE _fake_deps(
|
||||
technology_name_id INT ,
|
||||
technology_dependencies TEXT
|
||||
);
|
||||
CREATE OR REPLACE VIEW defs.technology_dependencies_view
|
||||
AS SELECT * FROM _fake_deps;
|
||||
|
||||
/* Insert empire states and data for fake views */
|
||||
INSERT INTO emp.technologies_v2 (
|
||||
empire_id , technology_name_id ,
|
||||
emptech_state , emptech_points , emptech_priority
|
||||
) VALUES (
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) ,
|
||||
'KNOWN' , NULL , NULL
|
||||
) , (
|
||||
_get_emp_name( 'emp2' ) , _get_string( 'tech1' ) ,
|
||||
'RESEARCH' , 228.9 , 0
|
||||
) , (
|
||||
_get_emp_name( 'emp3' ) , _get_string( 'tech1' ) ,
|
||||
'RESEARCH' , 114 , 1
|
||||
);
|
||||
INSERT INTO _fake_visibility VALUES(
|
||||
_get_emp_name( 'emp1' ) , _get_string( 'tech1' ) , TRUE
|
||||
) , (
|
||||
_get_emp_name( 'emp2' ) , _get_string( 'tech1' ) , TRUE
|
||||
) , (
|
||||
_get_emp_name( 'emp3' ) , _get_string( 'tech1' ) , FALSE
|
||||
);
|
||||
INSERT INTO _fake_deps VALUES( _get_string( 'tech1' ) , 'deps are here' );
|
||||
|
||||
-- ***** TESTS BEGIN HERE *****
|
||||
SELECT plan( 3 );
|
||||
|
||||
SELECT diag_test_name( 'emp.technologies_v2_view - Known technology' );
|
||||
SELECT set_eq( $$
|
||||
SELECT emptech_id , emptech_state::TEXT , emptech_visible ,
|
||||
technology_category , technology_name , technology_description ,
|
||||
emptech_points , emptech_priority IS NULL AS ep_null ,
|
||||
emptech_ratio IS NULL AS er_null ,
|
||||
technology_price , technology_dependencies
|
||||
FROM emp.technologies_v2_view
|
||||
WHERE empire_id = _get_emp_name( 'emp1' )
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp1' ) || ',tech1,true' , 'KNOWN' , TRUE ,
|
||||
'techCategory1' , 'tech1' , 'techDescription1' ,
|
||||
456 , TRUE , TRUE , 123 , 'deps are here'
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'emp.technologies_v2_view - In-progress, visible technology' );
|
||||
SELECT set_eq( $$
|
||||
SELECT emptech_id , emptech_state::TEXT , emptech_visible ,
|
||||
technology_category , technology_name , technology_description ,
|
||||
emptech_points , emptech_priority , emptech_ratio ,
|
||||
technology_price , technology_dependencies
|
||||
FROM emp.technologies_v2_view
|
||||
WHERE empire_id = _get_emp_name( 'emp2' )
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp2' ) || ',tech1,true' , 'RESEARCH' , TRUE ,
|
||||
'techCategory1' , 'tech1' , 'techDescription1' ,
|
||||
228 , 0 , 50 , 123 , 'deps are here'
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'emp.technologies_v2_view - In-progress, unknown technology' );
|
||||
SELECT set_eq( $$
|
||||
SELECT emptech_id , emptech_state::TEXT , emptech_visible ,
|
||||
technology_category , technology_name IS NULL AS n1 , technology_description IS NULL AS n2 ,
|
||||
emptech_points IS NULL AS n3 , emptech_priority , emptech_ratio ,
|
||||
technology_price IS NULL AS n4, technology_dependencies
|
||||
FROM emp.technologies_v2_view
|
||||
WHERE empire_id = _get_emp_name( 'emp3' )
|
||||
$$ , $$ VALUES(
|
||||
_get_emp_name( 'emp3' ) || ',tech1,false' , 'RESEARCH' , FALSE ,
|
||||
'techCategory1' , TRUE, TRUE ,
|
||||
TRUE , 1 , 25 , TRUE , 'deps are here'
|
||||
) $$ );
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
Reference in a new issue