/* * Utility functions used by unit tests * * Resources and natural resources */ /* * Function that creates some quantity of resources * All resources are created using the specified prefix for the strings */ CREATE FUNCTION _create_resources( _quantity INT , _prefix TEXT ) RETURNS VOID AS $$ DECLARE i INT; BEGIN PERFORM _create_test_strings( _quantity , _prefix ); PERFORM _create_test_strings( _quantity , _prefix || 'Description' ); i := 0; WHILE i < _quantity LOOP i := i + 1; INSERT INTO defs.resources ( resource_name_id , resource_description_id , resource_weight ) VALUES ( _get_string( _prefix || i::TEXT ) , _get_string( _prefix || 'Description' || i::TEXT ) , i ); END LOOP; END; $$ LANGUAGE PLPGSQL; /* * Function that creates some quantity of /natural/ resources * All resources are created using the specified prefix for the strings */ CREATE FUNCTION _create_natural_resources( _quantity INT , _prefix TEXT ) RETURNS VOID AS $$ DECLARE i INT; BEGIN PERFORM _create_resources( _quantity , _prefix ); i := 0; WHILE i < _quantity LOOP i := i + 1; INSERT INTO defs.natural_resources( resource_name_id , natres_p_presence , natres_quantity_avg , natres_quantity_dev , natres_difficulty_avg , natres_difficulty_dev , natres_recovery_avg , natres_recovery_dev ) VALUES ( _get_string( _prefix || i::TEXT ) , 0.5 , 100 , 1 , 0.5 , 0.05 , 0.5 , 0.05 ); END LOOP; END; $$ LANGUAGE PLPGSQL;