Database definition & tests organisation
* The main loader script has been updated to generate the list of files it needs to load automatically. As a consequence, files that contained manually-maintained lists of scripts have been removed, and definition directories have been renamed accordingly. * PostgreSQL extension loading and configuration has been moved to a separate script to be loaded automatically in the main transaction. * Data and function definition scripts that had the -data or -functions suffix have been renamed (the suffix is unnecessary). * Unit tests have been reorganised to follow the definition's structure. * Documentation has been improved
This commit is contained in:
parent
b054a379a9
commit
e50775ec76
112 changed files with 78 additions and 144 deletions
legacyworlds-server-data/db-structure/tests/admin/040-functions
025-resources
010-uoc-resource-internal.sql020-uoc-resource.sql030-uoc-natres-internal.sql040-uoc-natural-resource.sql
050-computation
053-generator-basics
055-generator-resources
010-collect-resprov-statistics.sql020-compute-rpp-delta.sql030-create-resource-provider.sql040-create-resource-providers-with-type.sql050-create-resource-providers.sql
145-resource-providers
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Test the defs.uoc_resource_internal() function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* We need a few strings to be used when creating resource definitions, and a natural resource. */
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
SELECT _create_test_strings( 7 );
|
||||
SELECT _create_natural_resources( 1 , 'natRes' );
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 15 );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation without category' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test3' , 'test4' , NULL , 1 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation results without category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation with category' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test5' , 'test6' , 'test7' , 1 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - creation results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , _get_string( 'test6' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - update without category' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test3' , 'test7' , NULL , 2 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - update results without category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test7' ) , 2 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - update with category' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test3' , 'test4' , 'test7' , 1 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - update results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - incorrect name string' );
|
||||
SELECT is( defs.uoc_resource_internal( 'does-not-exist' , 'test2' , NULL , 1 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - incorrect description string' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test1' , 'does-not-exist' , NULL , 1 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - incorrect category string' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test1' , 'test2' , 'does-not-exist' , 1 ) , 'BAD_STRINGS' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - duplicate description on new resource' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test1' , 'test4' , NULL , 1 ) , 'DUP_DESCR' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - duplicate description on existing resource' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test5' , 'test4' , NULL , 1 ) , 'DUP_DESCR' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - update on natural resource' );
|
||||
SELECT is( defs.uoc_resource_internal( 'natRes1' , 'test2' , NULL , 1 ) , 'BAD_TYPE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource_internal() - weight <= 0' );
|
||||
SELECT is( defs.uoc_resource_internal( 'test1' , 'test2' , NULL , 0 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Test the defs.uoc_resource() functions
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* We need a few strings to be used when creating resource definitions, and a natural resource. */
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
SELECT _create_test_strings( 7 );
|
||||
SELECT _create_natural_resources( 1 , 'natRes' );
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 22 );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (no category)' );
|
||||
SELECT is( defs.uoc_resource( NULL , 'test2' , 1 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL description (no category)' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , NULL , 1 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL weight (no category)' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'test2' , NULL ) , NULL );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL name (with category)' );
|
||||
SELECT is( defs.uoc_resource( NULL , 'test2' , 'test3' , 1 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL description (with category)' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , NULL , 'test3' , 1 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL category' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'test2' , NULL , 1 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - NULL weight (with category)' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'test2' , 'test3' , NULL ) , NULL );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - creation without category' );
|
||||
SELECT is( defs.uoc_resource( 'test3' , 'test4' , 1 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - creation results without category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - creation with category' );
|
||||
SELECT is( defs.uoc_resource( 'test5' , 'test6' , 'test7' , 1 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - creation results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , _get_string( 'test6' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - update without category' );
|
||||
SELECT is( defs.uoc_resource( 'test3' , 'test7', 2 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - update results without category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test7' ) , 2 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - update with category' );
|
||||
SELECT is( defs.uoc_resource( 'test3' , 'test4' , 'test7' , 1 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - update results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - incorrect name string' );
|
||||
SELECT is( defs.uoc_resource( 'does-not-exist' , 'test2' , 1 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - incorrect description string' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'does-not-exist' , 1 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - incorrect category string' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'test2' , 'does-not-exist' , 1 ) , 'BAD_STRINGS' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - duplicate description on new resource' );
|
||||
SELECT is( defs.uoc_resource( 'test1' , 'test4' , 1 ) , 'DUP_DESCR' );
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - duplicate description on existing resource' );
|
||||
SELECT is( defs.uoc_resource( 'test5' , 'test4' , 1 ) , 'DUP_DESCR' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - update on natural resource' );
|
||||
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 1 ) , 'BAD_TYPE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_resource() - weight <= 0' );
|
||||
SELECT is( defs.uoc_resource( 'natRes1' , 'test2' , 0 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Test the defs.uoc_natres_internal() function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* We need a few strings to be used when creating resource definitions, and a basic resource. */
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
SELECT _create_test_strings( 7 );
|
||||
SELECT _create_resources( 1 , 'basicRes' );
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 37 );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation without category' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test3' , 'test4' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation results without category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation results without category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation with category' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test6' , 'test7' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation results with category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , _get_string( 'test6' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - creation results with category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update without category' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test3' , 'test7' , NULL , 2 ,
|
||||
0.3 , 300 , 30 , 0.3 , 0.03 , 0.3 , 0.03 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update results without category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test7' ) , 2 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update results without category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.3::DOUBLE PRECISION , 300::DOUBLE PRECISION ,
|
||||
30::DOUBLE PRECISION , 0.3::DOUBLE PRECISION , 0.03::DOUBLE PRECISION ,
|
||||
0.3::DOUBLE PRECISION , 0.03::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update with category' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test3' , 'test4' , 'test7' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update results with category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - incorrect name string' );
|
||||
SELECT is( defs.uoc_natres_internal( 'does-not-exist' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - incorrect description string' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test1' , 'does-not-exist' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - incorrect category string' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test1' , 'test2' , 'does-not-exist' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - duplicate description on new resource' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test1' , 'test4' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'DUP_DESCR' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - duplicate description on existing resource' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test4' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'DUP_DESCR' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - update on basic resource' );
|
||||
SELECT is( defs.uoc_natres_internal( 'basicRes1' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_TYPE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - weight <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 0 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - P(presence) <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - P(presence) >= 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - max. quantity <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 0 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - quantity dev. < 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , -1 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - quantity max. - dev. <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 100 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. = 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0 , 0 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. < 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , -0.00001 , 0 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. = 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 1 , 0 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. > 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 1.00001 , 0 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty dev. < 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , -1 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. - dev. < 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.25 , 0.5 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - difficulty max. + dev. > 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.75 , 0.5 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery max. <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0 , 0 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery max. = 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 1 , 0 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery max. > 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 1.0001 , 0 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery dev. < 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , -0.25 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery max. - dev. <= 0' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.25 , 0.25 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natres_internal() - recovery max. + dev. > 1' );
|
||||
SELECT is( defs.uoc_natres_internal( 'test5' , 'test2' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,242 @@
|
|||
/*
|
||||
* Test the defs.uoc_natural_resource() functions
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* We need a few strings to be used when creating resource definitions, and a basic resource. */
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
SELECT _create_test_strings( 7 );
|
||||
SELECT _create_resources( 1 , 'basicRes' );
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 58 );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL name (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( NULL , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL description (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL weight (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , NULL ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL presence (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
NULL , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average quantity (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , NULL , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL quantity deviation (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , NULL , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average difficulty (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , NULL , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL difficulty deviation (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , NULL , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average recovery (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , NULL , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL recovery deviation (no category)' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , NULL ) , NULL );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL name' );
|
||||
SELECT is( defs.uoc_natural_resource( NULL , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL description' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , NULL , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL category' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , NULL , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL weight' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , NULL ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL presence' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
NULL , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average quantity' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , NULL , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL quantity deviation' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , NULL , 0.5 , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average difficulty' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , NULL , 0.05 , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL difficulty deviation' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , NULL , 0.5 , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL average recovery' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , NULL , 0.05 ) , NULL );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - NULL recovery deviation' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 'test5' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , NULL ) , NULL );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation without category' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test3' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation results without category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation results without category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation with category' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test6' , 'test7' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'CREATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation results with category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , _get_string( 'test6' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - creation results with category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test5' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test5' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update without category' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test3' , 'test7' , 2 ,
|
||||
0.3 , 300 , 30 , 0.3 , 0.03 , 0.3 , 0.03 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update results without category - basic' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT resource_name_id , resource_description_id , resource_weight
|
||||
FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' )
|
||||
AND resource_category_id IS NULL $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test7' ) , 2 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update results without category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.3::DOUBLE PRECISION , 300::DOUBLE PRECISION ,
|
||||
30::DOUBLE PRECISION , 0.3::DOUBLE PRECISION , 0.03::DOUBLE PRECISION ,
|
||||
0.3::DOUBLE PRECISION , 0.03::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update with category' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test3' , 'test4' , 'test7' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update results with category' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , _get_string( 'test4' ) , _get_string( 'test7' ) , 1 ) $$
|
||||
);
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update results with category - nat. res.' );
|
||||
SELECT results_eq(
|
||||
$$ SELECT * FROM defs.natural_resources
|
||||
WHERE resource_name_id = _get_string( 'test3' ) $$ ,
|
||||
$$ VALUES ( _get_string( 'test3' ) , 0.5::DOUBLE PRECISION , 100::DOUBLE PRECISION ,
|
||||
50::DOUBLE PRECISION , 0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ,
|
||||
0.5::DOUBLE PRECISION , 0.05::DOUBLE PRECISION ) $$
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - incorrect name string' );
|
||||
SELECT is( defs.uoc_natural_resource( 'does-not-exist' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - incorrect description string' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'does-not-exist' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - incorrect category string' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test2' , 'does-not-exist' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_STRINGS' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - duplicate description on new resource' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test1' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'DUP_DESCR' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - duplicate description on existing resource' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test4' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'DUP_DESCR' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - update on basic resource' );
|
||||
SELECT is( defs.uoc_natural_resource( 'basicRes1' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_TYPE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - weight <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 0 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - P(presence) <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - P(presence) >= 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0 , 100 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - max. quantity <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 0 , 50 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - quantity dev. < 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , -1 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - quantity max. - dev. <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 100 , 0.5 , 0.05 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. = 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0 , 0 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. < 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , -0.00001 , 0 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. = 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 1 , 0 , 0.5 , 0.05 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. > 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 1.00001 , 0 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty dev. < 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , -1 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. - dev. < 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.25 , 0.5 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - difficulty max. + dev. > 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.75 , 0.5 , 0.5 , 0.05 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery max. <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0 , 0 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery max. = 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 1 , 0 ) , 'UPDATED' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery max. > 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 1.0001 , 0 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery dev. < 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.5 , -0.25 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery max. - dev. <= 0' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.25 , 0.25 ) , 'BAD_VALUE' );
|
||||
SELECT diag_test_name( 'defs.uoc_natural_resource() - recovery max. + dev. > 1' );
|
||||
SELECT is( defs.uoc_natural_resource( 'test5' , 'test2' , 1 ,
|
||||
0.5 , 100 , 50 , 0.5 , 0.05 , 0.75 , 0.5 ) , 'BAD_VALUE' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Test the verse.get_random_part() function
|
||||
*/
|
||||
BEGIN;
|
||||
SELECT plan( 6 );
|
||||
|
||||
/* First set of tests: results of the function with a fake
|
||||
* verse.random_deviation() that always returns the minimal possible
|
||||
* value.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.random_deviation( _mean DOUBLE PRECISION , _deviation DOUBLE PRECISION )
|
||||
RETURNS DOUBLE PRECISION
|
||||
STRICT VOLATILE
|
||||
AS $$
|
||||
SELECT $1 - $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Single part, minimal random value' );
|
||||
SELECT is( verse.get_random_part( 0.5 , 1 , 0.5 , 0.25 ) , 0.5::DOUBLE PRECISION );
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Two parts, some extra quantity, minimal random value' );
|
||||
SELECT is( verse.get_random_part( 0.75 , 2 , 0.5 , 0.25 ) , 0.25::DOUBLE PRECISION );
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Two parts, maximal quantity, minimal random value' );
|
||||
SELECT is( verse.get_random_part( 1.5 , 2 , 0.5 , 0.25 ) , 0.75::DOUBLE PRECISION );
|
||||
|
||||
/* Second set of tests: results of the function with a fake
|
||||
* verse.random_deviation() that always returns the maximal possible
|
||||
* value.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.random_deviation( _mean DOUBLE PRECISION , _deviation DOUBLE PRECISION )
|
||||
RETURNS DOUBLE PRECISION
|
||||
STRICT VOLATILE
|
||||
AS $$
|
||||
SELECT $1 + $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Single part, maximal random value' );
|
||||
SELECT is( verse.get_random_part( 0.5 , 1 , 0.5 , 0.25 ) , 0.5::DOUBLE PRECISION );
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Two parts, some extra quantity, maximal random value' );
|
||||
SELECT is( verse.get_random_part( 1 , 2 , 0.5 , 0.25 ) , 0.75::DOUBLE PRECISION );
|
||||
SELECT diag_test_name( 'verse.get_random_part() - Two parts, minimal quantity, maximal random value' );
|
||||
SELECT is( verse.get_random_part( 0.5 , 2 , 0.5 , 0.25 ) , 0.25::DOUBLE PRECISION );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Test the verse.list_random_planets_in() function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* We need two systems with one planet each. Systems will be located at
|
||||
* (0,0) and (1,1).
|
||||
*/
|
||||
\i utils/strings.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
\i utils/universe.sql
|
||||
SELECT _create_raw_planets( 10 , 'test' );
|
||||
|
||||
/***** TESTS BEGIN HERE *****/
|
||||
SELECT plan( 5 );
|
||||
|
||||
SELECT diag_test_name( 'verse.list_random_planets_in() - Empty set if count = 0' );
|
||||
SELECT is_empty( $$
|
||||
SELECT * FROM verse.list_random_planets_in( ROW( 0 , 0 , 1 , 1 ) , 0 )
|
||||
$$ );
|
||||
|
||||
SELECT diag_test_name( 'verse.list_random_planets_in() - Empty set if outside of existing universe' );
|
||||
SELECT is_empty( $$
|
||||
SELECT * FROM verse.list_random_planets_in( ROW( 2 , 2 , 3 , 3 ) , 2 )
|
||||
$$ );
|
||||
|
||||
SELECT diag_test_name( 'verse.list_random_planets_in() - Requested count > actual count' );
|
||||
SELECT is( COUNT(*) , 5::BIGINT )
|
||||
FROM verse.list_random_planets_in( ROW( 1 , 1 , 2 , 2 ) , 7 );
|
||||
|
||||
SELECT diag_test_name( 'verse.list_random_planets_in() - Requested count = actual count' );
|
||||
SELECT is( COUNT(*) , 5::BIGINT )
|
||||
FROM verse.list_random_planets_in( ROW( 1 , 1 , 2 , 2 ) , 5 );
|
||||
|
||||
SELECT diag_test_name( 'verse.list_random_planets_in() - Requested count < actual count' );
|
||||
SELECT is( COUNT(*) , 4::BIGINT )
|
||||
FROM verse.list_random_planets_in( ROW( 1 , 1 , 2 , 2 ) , 4 );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Test the verse.collect_resprov_statistics( ) function
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
\i utils/universe.sql
|
||||
SELECT _create_natural_resources( 2 , 'testResource' );
|
||||
SELECT _create_raw_planets( 5 , 'testPlanet' );
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 6 );
|
||||
|
||||
SELECT verse.collect_resprov_statistics( );
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - Temporary table creation' );
|
||||
SELECT has_table( 'rp_stats' );
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - Temporary table rows' );
|
||||
SELECT is( COUNT(*)::INT , 2 ) FROM rp_stats;
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - rp_stats contains definition data' );
|
||||
SELECT is( COUNT(*)::INT , 2 )
|
||||
FROM (
|
||||
SELECT ( d.natres_quantity_avg = s.quantity_avg
|
||||
AND d.natres_quantity_dev = s.quantity_dev
|
||||
AND d.natres_difficulty_avg = s.difficulty_avg
|
||||
AND d.natres_difficulty_dev = s.difficulty_dev
|
||||
AND d.natres_recovery_avg = s.recovery_avg
|
||||
AND d.natres_recovery_dev = s.recovery_dev
|
||||
AND d.natres_p_presence = s.presence ) AS ok
|
||||
FROM rp_stats s
|
||||
INNER JOIN defs.natural_resources d
|
||||
USING ( resource_name_id )
|
||||
) sq
|
||||
WHERE sq.ok;
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - rp_stats contains planet counts' );
|
||||
SELECT is( COUNT(*)::INT , 2 )
|
||||
FROM (
|
||||
SELECT planets = 5 AS ok
|
||||
FROM rp_stats
|
||||
) sq
|
||||
WHERE sq.ok;
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - rp_stats sums at 0 with no providers' );
|
||||
SELECT is( COUNT(*)::INT , 2 )
|
||||
FROM (
|
||||
SELECT ( providers = 0 AND quantity = 0
|
||||
AND difficulty = 0 AND recovery = 0 ) AS ok
|
||||
FROM rp_stats
|
||||
) sq
|
||||
WHERE sq.ok;
|
||||
|
||||
DROP TABLE rp_stats;
|
||||
SELECT _create_resource_provider( 'testPlanet1' , 'testResource1' );
|
||||
SELECT verse.collect_resprov_statistics( );
|
||||
|
||||
SELECT diag_test_name( 'verse.collect_resprov_statistics( ) - rp_stats sums' );
|
||||
SELECT is( COUNT(*)::INT , 1 )
|
||||
FROM (
|
||||
SELECT ( resource_name_id = _get_string( 'testResource1' )
|
||||
AND providers = 1 AND quantity = 100
|
||||
AND difficulty = 0.5 AND recovery = 0.5 ) AS ok
|
||||
FROM rp_stats
|
||||
) sq
|
||||
WHERE sq.ok;
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Test the verse.compute_rpp_delta( ) function
|
||||
*/
|
||||
BEGIN;
|
||||
SELECT plan( 12 );
|
||||
|
||||
/* First set of tests: results of the function with a fake
|
||||
* verse.random_deviation() that always returns the minimal possible
|
||||
* value.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.random_deviation( _mean DOUBLE PRECISION , _deviation DOUBLE PRECISION )
|
||||
RETURNS DOUBLE PRECISION
|
||||
STRICT VOLATILE
|
||||
AS $$
|
||||
SELECT $1 - $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - No existing value, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 0 , 10 , 0 , 1 , 0.5 )::NUMERIC , 5.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value below minimum, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 0 , 1 , 0.5 )::NUMERIC , 10.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at minimum, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 5 , 1 , 0.5 )::NUMERIC , 5.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at average, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 10 , 1 , 0.5 )::NUMERIC , 5.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at maximum, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 15 , 1 , 0.5 )::NUMERIC , 5.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value over maximum, random at minimal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 20 , 1 , 0.5 )::NUMERIC , 5.0 );
|
||||
|
||||
/* Second set of tests: results of the function with a fake
|
||||
* verse.random_deviation() that always returns the maximal possible
|
||||
* value.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.random_deviation( _mean DOUBLE PRECISION , _deviation DOUBLE PRECISION )
|
||||
RETURNS DOUBLE PRECISION
|
||||
STRICT VOLATILE
|
||||
AS $$
|
||||
SELECT $1 + $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - No existing value, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 0 , 10 , 0 , 1 , 0.5 )::NUMERIC , 15.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value below minimum, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 0 , 1 , 0.5 )::NUMERIC , 15.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at minimum, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 5 , 1 , 0.5 )::NUMERIC , 15.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at average, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 10 , 1 , 0.5 )::NUMERIC , 15.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value at maximum, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 15 , 1 , 0.5 )::NUMERIC , 15.0 );
|
||||
SELECT diag_test_name( 'verse.compute_rpp_delta( ) - Existing value over maximum, random at maximal value' );
|
||||
SELECT is( verse.compute_rpp_delta( 10 , 10 , 20 , 1 , 0.5 )::NUMERIC , 10.0 );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Test the verse.create_resource_provider( ) function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* Before any actual testing, we need to drop FK constraints on the RP
|
||||
* table and create a table which will contain the results of the
|
||||
* function.
|
||||
*/
|
||||
|
||||
ALTER TABLE verse.resource_providers
|
||||
DROP CONSTRAINT fk_resprov_planet ,
|
||||
DROP CONSTRAINT fk_resprov_resource;
|
||||
|
||||
CREATE TEMPORARY TABLE test_result(
|
||||
_providers_left INT ,
|
||||
_tot_quantity DOUBLE PRECISION ,
|
||||
_tot_difficulty DOUBLE PRECISION ,
|
||||
_tot_recovery DOUBLE PRECISION
|
||||
) ON COMMIT DROP;
|
||||
|
||||
/* Now we call the function using a crafted resource statistics row which
|
||||
* will make it easy to check the results.
|
||||
*/
|
||||
INSERT INTO test_result
|
||||
SELECT * FROM verse.create_resource_provider( 12 ,
|
||||
ROW( 34 , 0.0 , 0.0 , 0.0 , 0.0 , 5.0 , 0.0 , 0.0 , 0.75 , 0.0 , 0.0 , 0.5 , 0 ) ,
|
||||
2 , 10 , 1.5 , 1 );
|
||||
|
||||
|
||||
/***** TESTS BEGIN HERE *****/
|
||||
SELECT plan( 11 );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Output exists' );
|
||||
SELECT is( COUNT(*)::INT , 1 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - _providers_left updated' );
|
||||
SELECT is( _providers_left , 1 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - _tot_quantity updated' );
|
||||
SELECT is( _tot_quantity::NUMERIC , 5.0 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - _tot_difficulty updated' );
|
||||
SELECT is( _tot_difficulty::NUMERIC , 0.75 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - _tot_recovery updated' );
|
||||
SELECT is( _tot_recovery::NUMERIC , 0.5 ) FROM test_result;
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider exists' );
|
||||
SELECT is( COUNT(*)::INT , 1 ) FROM verse.resource_providers;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider primary key' );
|
||||
SELECT is( COUNT(*)::INT , 1 ) FROM verse.resource_providers
|
||||
WHERE planet_id = 12 AND resource_name_id = 34;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider is full' );
|
||||
SELECT is( COUNT(*)::INT , 1 ) FROM verse.resource_providers
|
||||
WHERE resprov_quantity = resprov_quantity_max;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider maximal quantity' );
|
||||
SELECT is( resprov_quantity_max::NUMERIC , 5.0 ) FROM verse.resource_providers;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider extraction difficulty' );
|
||||
SELECT is( resprov_difficulty::NUMERIC , 0.75 ) FROM verse.resource_providers;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( ) - Resource provider recovery rate' );
|
||||
SELECT is( resprov_recovery::NUMERIC , 0.5 ) FROM verse.resource_providers;
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Check the variant of verse.create_resource_providers( ) which takes a
|
||||
* resource statistics record as a parameter.
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* Temporary table which will store information about calls to the
|
||||
* verse.create_resource_provider( ) function
|
||||
*/
|
||||
CREATE TEMPORARY TABLE test_result(
|
||||
planet INT ,
|
||||
resource INT ,
|
||||
quantity DOUBLE PRECISION ,
|
||||
difficulty DOUBLE PRECISION ,
|
||||
recovery DOUBLE PRECISION
|
||||
) ON COMMIT DROP;
|
||||
|
||||
/* Replace verse.list_random_planets_in() with a function that simply
|
||||
* counts.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.list_random_planets_in(
|
||||
_area verse.generator_area_type ,
|
||||
_count INT )
|
||||
RETURNS SETOF INT
|
||||
STRICT VOLATILE
|
||||
SECURITY INVOKER
|
||||
AS $list_random_planets_in$
|
||||
DECLARE
|
||||
i INT;
|
||||
BEGIN
|
||||
FOR i IN 1 .. _count
|
||||
LOOP
|
||||
RETURN NEXT i;
|
||||
END LOOP;
|
||||
END;
|
||||
$list_random_planets_in$ LANGUAGE PLPGSQL;
|
||||
|
||||
/* Replace verse.create_resource_provider( ) with a function that writes
|
||||
* to the test_result temporary table.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.create_resource_provider(
|
||||
_planet INT ,
|
||||
_data verse.resprov_generator_type ,
|
||||
INOUT _providers_left INT ,
|
||||
INOUT _tot_quantity DOUBLE PRECISION ,
|
||||
INOUT _tot_difficulty DOUBLE PRECISION ,
|
||||
INOUT _tot_recovery DOUBLE PRECISION )
|
||||
STRICT VOLATILE
|
||||
SECURITY INVOKER
|
||||
AS $create_resource_provider$
|
||||
BEGIN
|
||||
INSERT INTO test_result VALUES(
|
||||
_planet , _data.resource_name_id ,
|
||||
_tot_quantity / _providers_left::DOUBLE PRECISION ,
|
||||
_tot_difficulty / _providers_left::DOUBLE PRECISION ,
|
||||
_tot_recovery / _providers_left::DOUBLE PRECISION
|
||||
);
|
||||
|
||||
_tot_quantity := ( _providers_left - 1 ) * _tot_quantity / _providers_left;
|
||||
_tot_difficulty := ( _providers_left - 1 ) * _tot_difficulty / _providers_left;
|
||||
_tot_recovery := ( _providers_left - 1 ) * _tot_recovery / _providers_left;
|
||||
_providers_left := _providers_left - 1;
|
||||
END;
|
||||
$create_resource_provider$ LANGUAGE PLPGSQL;
|
||||
|
||||
/***** TESTS BEGIN HERE *****/
|
||||
SELECT plan( 11 );
|
||||
|
||||
|
||||
/* First set of test: empty universe */
|
||||
SELECT verse.create_resource_providers(
|
||||
ROW( 0 , 0 , 1 , 1 ) ,
|
||||
ROW( 42 , 0.0 , 0.0 , 0.5 , 0.0 , 5.0 , 0.0 , 0.0 , 0.75 , 0.0 , 0.0 , 0.5 , 0 )
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Providers created' );
|
||||
SELECT is( COUNT(*)::INT , 10 ) FROM test_result WHERE resource = 42;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Planet identifiers' );
|
||||
SELECT results_eq(
|
||||
'SELECT planet FROM test_result ORDER BY planet' ,
|
||||
ARRAY[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
|
||||
);
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Total quantity' );
|
||||
SELECT is( SUM(quantity)::NUMERIC , 50.0 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Quantity per planet' );
|
||||
SELECT is( COUNT(*)::INT , 10 ) FROM test_result
|
||||
WHERE quantity = 5;
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Total difficulty' );
|
||||
SELECT is( SUM(difficulty)::NUMERIC , 7.5 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Difficulty per planet' );
|
||||
SELECT is( COUNT(*)::INT , 10 ) FROM test_result
|
||||
WHERE difficulty = 0.75;
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Total recovery rate' );
|
||||
SELECT is( SUM(recovery)::NUMERIC , 5.0 ) FROM test_result;
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Empty universe - Recovery rate per planet' );
|
||||
SELECT is( COUNT(*)::INT , 10 ) FROM test_result
|
||||
WHERE recovery = 0.5;
|
||||
|
||||
|
||||
/* Second set of tests: balancing providers presence */
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Providers created in balanced universe' );
|
||||
DELETE FROM test_result;
|
||||
SELECT verse.create_resource_providers(
|
||||
ROW( 0 , 0 , 1 , 1 ) ,
|
||||
ROW( 42 , 20.0 , 10.0 , 0.5 , 0.0 , 5.0 , 0.0 , 0.0 , 0.75 , 0.0 , 0.0 , 0.5 , 0 )
|
||||
);
|
||||
SELECT is( COUNT(*)::INT , 10 ) FROM test_result WHERE resource = 42;
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Providers created in universe with low providers count' );
|
||||
DELETE FROM test_result;
|
||||
SELECT verse.create_resource_providers(
|
||||
ROW( 0 , 0 , 1 , 1 ) ,
|
||||
ROW( 42 , 20.0 , 5.0 , 0.5 , 0.0 , 5.0 , 0.0 , 0.0 , 0.75 , 0.0 , 0.0 , 0.5 , 0 )
|
||||
);
|
||||
SELECT is( COUNT(*)::INT , 15 ) FROM test_result WHERE resource = 42;
|
||||
|
||||
SELECT diag_test_name( 'verse.create_resource_provider( area , stats ) - Providers created in universe with high providers count' );
|
||||
DELETE FROM test_result;
|
||||
SELECT verse.create_resource_providers(
|
||||
ROW( 0 , 0 , 1 , 1 ) ,
|
||||
ROW( 42 , 20.0 , 15.0 , 0.5 , 0.0 , 5.0 , 0.0 , 0.0 , 0.75 , 0.0 , 0.0 , 0.5 , 0 )
|
||||
);
|
||||
SELECT is( COUNT(*)::INT , 5 ) FROM test_result WHERE resource = 42;
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Test the "main" verse.create_resource_providers( ) function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* Create a dummy rp_stats table that contains a few identifiers */
|
||||
CREATE TEMP TABLE rp_stats
|
||||
OF verse.resprov_generator_type
|
||||
ON COMMIT DROP;
|
||||
INSERT INTO rp_stats ( resource_name_id )
|
||||
VALUES ( 1 ) , ( 2 ) , ( 3 ) , ( 4 );
|
||||
|
||||
/* Replace the verse.create_resource_providers( area , type ) function
|
||||
* with a function that deletes the resource type it was given from
|
||||
* rp_stats.
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION verse.create_resource_providers(
|
||||
_area verse.generator_area_type ,
|
||||
_data verse.resprov_generator_type )
|
||||
RETURNS VOID
|
||||
STRICT VOLATILE
|
||||
SECURITY INVOKER
|
||||
AS $create_resource_providers$
|
||||
BEGIN
|
||||
DELETE FROM rp_stats WHERE resource_name_id = _data.resource_name_id;
|
||||
END;
|
||||
$create_resource_providers$ LANGUAGE PLPGSQL;
|
||||
|
||||
SELECT plan(1);
|
||||
SELECT diag_test_name( 'verse.create_resource_providers( area ) - Calls to per-type function' );
|
||||
SELECT verse.create_resource_providers( ROW( 0 , 0 , 1 , 1 ) );
|
||||
SELECT is( COUNT(*)::INT , 0 ) FROM rp_stats;
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* Test the verse.compute_provider_regeneration() function
|
||||
*/
|
||||
BEGIN;
|
||||
|
||||
/* Define the necessary constants using default values */
|
||||
SELECT sys.uoc_constant( 'game.resources.recovery' , '(test)' , 'Resources' , 0.01 );
|
||||
SELECT sys.uoc_constant( 'game.resources.recoveryDampening' , '(test)' , 'Resources' , 1.5 );
|
||||
|
||||
/* Make sure the functions are not immutable during the tests */
|
||||
ALTER FUNCTION sys.get_constant( TEXT ) VOLATILE;
|
||||
ALTER FUNCTION verse.compute_provider_regeneration( DOUBLE PRECISION , DOUBLE PRECISION , DOUBLE PRECISION ) VOLATILE;
|
||||
|
||||
/****** TESTS BEGIN HERE ******/
|
||||
SELECT plan( 6 );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - no regeneration at maximal quantity' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
rr DOUBLE PRECISION;
|
||||
BEGIN
|
||||
rr := 0.05;
|
||||
WHILE rr < 1
|
||||
LOOP
|
||||
IF verse.compute_provider_regeneration( 100.0 , 100.0 , rr ) > 100.0
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
rr := rr + 0.05;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - regeneration >= 0' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
qt DOUBLE PRECISION;
|
||||
rr DOUBLE PRECISION;
|
||||
BEGIN
|
||||
qt := 0;
|
||||
WHILE qt < 100.0
|
||||
LOOP
|
||||
rr := 0.05;
|
||||
WHILE rr < 1
|
||||
LOOP
|
||||
IF verse.compute_provider_regeneration( qt , 100.0 , rr ) <= qt
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
rr := rr + 0.05;
|
||||
END LOOP;
|
||||
qt := qt + 5;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - higher quantity => slower regeneration' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
pdiff DOUBLE PRECISION;
|
||||
diff DOUBLE PRECISION;
|
||||
qt DOUBLE PRECISION;
|
||||
rr DOUBLE PRECISION;
|
||||
BEGIN
|
||||
rr := 0.05;
|
||||
WHILE rr < 1
|
||||
LOOP
|
||||
qt := 0;
|
||||
WHILE qt < 100.0
|
||||
LOOP
|
||||
diff := verse.compute_provider_regeneration( qt , 100.0 , rr ) - qt;
|
||||
IF qt <> 0 AND diff >= pdiff
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
pdiff := diff;
|
||||
qt := qt + 5;
|
||||
END LOOP;
|
||||
rr := rr + 0.05;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - higher recovery rate => faster regeneration' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
pdiff DOUBLE PRECISION;
|
||||
diff DOUBLE PRECISION;
|
||||
qt DOUBLE PRECISION;
|
||||
rr DOUBLE PRECISION;
|
||||
BEGIN
|
||||
qt := 0;
|
||||
WHILE qt < 100.0
|
||||
LOOP
|
||||
rr := 0.05;
|
||||
WHILE rr < 1
|
||||
LOOP
|
||||
diff := verse.compute_provider_regeneration( qt , 100.0 , rr ) - qt;
|
||||
IF rr > 0.06 AND diff <= pdiff
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
pdiff := diff;
|
||||
rr := rr + 0.05;
|
||||
END LOOP;
|
||||
qt := qt + 5;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - effect of game.resources.recovery' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
pdiff DOUBLE PRECISION;
|
||||
diff DOUBLE PRECISION;
|
||||
qt DOUBLE PRECISION;
|
||||
rr DOUBLE PRECISION;
|
||||
BEGIN
|
||||
qt := 0;
|
||||
WHILE qt < 100.0
|
||||
LOOP
|
||||
rr := 0.01;
|
||||
WHILE rr < 1
|
||||
LOOP
|
||||
UPDATE sys.constant_definitions
|
||||
SET c_value = rr
|
||||
WHERE name = 'game.resources.recovery';
|
||||
diff := verse.compute_provider_regeneration( qt , 100.0 , 0.5 ) - qt;
|
||||
IF rr > 0.011 AND diff <= pdiff
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
pdiff := diff;
|
||||
rr := rr + 0.01;
|
||||
END LOOP;
|
||||
qt := qt + 5;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
UPDATE sys.constant_definitions
|
||||
SET c_value = 0.01
|
||||
WHERE name = 'game.resources.recovery';
|
||||
|
||||
|
||||
|
||||
SELECT diag_test_name( 'verse.compute_provider_regeneration() - effect of game.resources.recoveryDampening' );
|
||||
CREATE FUNCTION _run_tests( ) RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
pdiff DOUBLE PRECISION;
|
||||
diff DOUBLE PRECISION;
|
||||
qt DOUBLE PRECISION;
|
||||
rrd DOUBLE PRECISION;
|
||||
BEGIN
|
||||
qt := 5;
|
||||
WHILE qt < 100.0
|
||||
LOOP
|
||||
rrd := 1;
|
||||
WHILE rrd < 3
|
||||
LOOP
|
||||
UPDATE sys.constant_definitions
|
||||
SET c_value = rrd
|
||||
WHERE name = 'game.resources.recoveryDampening';
|
||||
diff := verse.compute_provider_regeneration( qt , 100.0 , 0.5 ) - qt;
|
||||
IF rrd > 1.01 AND diff >= pdiff
|
||||
THEN
|
||||
RETURN FALSE;
|
||||
END IF;
|
||||
pdiff := diff;
|
||||
rrd := rrd + 0.25;
|
||||
END LOOP;
|
||||
qt := qt + 5;
|
||||
END LOOP;
|
||||
RETURN TRUE;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
SELECT ok( _run_tests() );
|
||||
DROP FUNCTION _run_tests( );
|
||||
UPDATE sys.constant_definitions
|
||||
SET c_value = 1.5
|
||||
WHERE name = 'game.resources.recoveryDampening';
|
||||
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
Reference in a new issue