Any suggestions on how to write a test script to test a package. Some of the functions in the package are to_number_zero, CheckIfNumeric( STRING_IN IN VARCHAR2). I need to write some sort of test script for these functions. For example, the to_number_zero test should pass in an alphabetic string and check the result, then pass in a numeric string and check the result.
20 7685
not completely sure what all the functions do but it sounds straight forward enough. write a script that will spool to a file (for a record of the results), set echo and timing on to see all that is run and dbms_output everything to the spool file as well for all the answers.
make blocks within the main block with exception handlers so you can see all errors that occur.
From your post it is not clear what exactly is your requirment. Can you kindly post more clearly please.
Any suggestions on how to write a test script to test a package. Some of the functions in the package are to_number_zero, CheckIfNumeric( STRING_IN IN VARCHAR2). I need to write some sort of test script for these functions. For example, the to_number_zero test should pass in an alphabetic string and check the result, then pass in a numeric string and check the result.
Could you please post your functions soure code here for reference?
Here is my source code. Hope this will enable you guys to help me out.
--
-- Create to_date_null -- Function will convert to a date in the same way as the Oracle to_date
-- function. However rather than throw an exception on invalid input,
-- to_date_null will simply return a null date.
-- -
-
prompt Creating to_date_null function
-
CREATE OR REPLACE FUNCTION to_date_null
-
(strDate CHAR, strFormat CHAR)
-
RETURN DATE
-
DETERMINISTIC
-
IS
-
d_date DATE;
-
BEGIN
-
d_date := TO_DATE(strDate, strFormat);
-
RETURN d_date;
-
EXCEPTION
-
WHEN OTHERS THEN
-
RETURN NULL;
-
END to_date_null;
-
/
-
-
--
-
-- Create to_number_null -- Function will convert a string to number in the same way as the
-
-- Oracle to_number function. However rather than throw an exception
-
-- on invalid input, to_number_null will simply return a null number.
-
--
-
prompt Creating to_number_null function
-
CREATE OR REPLACE FUNCTION to_number_null
-
(strNumber CHAR)
-
RETURN NUMBER
-
DETERMINISTIC
-
IS
-
num_out NUMBER;
-
BEGIN
-
num_out := TO_NUMBER(strNumber);
-
RETURN num_out;
-
EXCEPTION
-
WHEN OTHERS THEN
-
RETURN NULL;
-
END to_number_null;
-
/
-
-
--
-
-- IsNumeric -- Function will test if a string is all numeric digits
-
--
-
prompt Creating IsNumeric function
-
CREATE OR REPLACE FUNCTION IsNumeric
-
(strIn VARCHAR2)
-
RETURN BOOLEAN
-
DETERMINISTIC
-
IS
-
strNonNumDigits VARCHAR2(4000);
-
BEGIN
-
-- Remove numeric digits from string
-
strNonNumDigits := translate(strIn, '0123456789', '');
-
-- Test if any chars are left
-
IF strNonNumDigits IS NULL THEN
-
return TRUE;
-
ELSE
-
return FALSE;
-
END IF;
-
END IsNumeric;
-
/
-
-
--
-
-- Create LASTNAME -- Function pulls the last name out
-
-- from the entire pat_name. Will work if there's
-
-- a comma or caret.
-
--
-
prompt Creating LASTNAME function
-
CREATE OR REPLACE FUNCTION LASTNAME(pat_name_in IN VARCHAR2)
-
RETURN VARCHAR2
-
DETERMINISTIC
-
IS
-
pname_out VARCHAR2(64);
-
theseperator NUMBER;
-
BEGIN
-
-- init pname_out
-
pname_out := pat_name_in;
-
-- replace ',' with '^'
-
pname_out := replace(pname_out, ',', '^');
-
pname_out := replace(pname_out, ' ', '^');
-
IF instr(pname_out, '^') > 0 THEN
-
-- Find last name only
-
pname_out := substr(pname_out, 1, instr(pname_out, '^')-1);
-
ELSE
-
-- Assume we only have a last name
-
pname_out := pname_out;
-
END IF;
-
-- return pname_out
-
RETURN (pname_out);
-
END;
-
/
-
-
--
-
-- Create FIRSTNAME -- Function pulls the first name out
-
-- from the entire pat_name. Will work if there's
-
-- a comma or caret.
-
--
-
prompt Creating FIRSTNAME function
-
CREATE OR REPLACE FUNCTION FIRSTNAME(pat_name_in IN VARCHAR2)
-
RETURN VARCHAR2
-
DETERMINISTIC
-
IS
-
pname_out VARCHAR2(64);
-
theseperator NUMBER;
-
BEGIN
-
--
-
-- Create FIRSTNAME -- Function pulls the first name out
-
-- from the entire pat_name. Will work if there's
-
-- a comma or caret.
-
--
-
-- init pname_out
-
pname_out := pat_name_in;
-
-- replace ',' with '^'
-
pname_out := replace(pname_out, ',', '^');
-
pname_out := replace(pname_out, ' ', '^');
-
IF instr(pname_out, '^',1,2) <> 0 THEN
-
-- Find first name only, with middle name in string
-
pname_out := substr(pname_out, instr(pname_out, '^')+1, instr(pname_out, '^', 1, 2) - instr(pname_out, '^') -1);
-
ELSIF instr(pname_out, '^') <> 0 THEN
-
-- Find first name only, no middle name
-
pname_out := substr(pname_out, instr(pname_out, '^')+1, LENGTH(pname_out) - (instr(pname_out, '^') -1));
-
ELSE
-
-- Assume we only have no first name
-
pname_out := NULL;
-
END IF;
-
-- return pname_out
-
RETURN (pname_out);
-
END;
-
/
-
-
--
-
-- Create MIDDLENAME -- Function pulls the middle name out
-
-- from the entire pat_name. Will work if there's
-
-- a comma or caret.
-
--
-
prompt Creating MIDDLENAME function
-
CREATE OR REPLACE FUNCTION MIDDLENAME(pat_name_in IN VARCHAR2)
-
RETURN VARCHAR2
-
DETERMINISTIC
-
IS
-
pname_out VARCHAR2(64);
-
theseperator NUMBER;
-
BEGIN
-
--
-
-- Create MIDDLENAME -- Function pulls the middle name out
-
-- from the entire pat_name. Will work if there's
-
-- a comma or caret.
-
--
-
-- init pname_out
-
pname_out := pat_name_in;
-
-- replace ',' with '^'
-
pname_out := replace(pname_out, ',', '^');
-
pname_out := replace(pname_out, ' ', '^');
-
IF instr(pname_out, '^',1,2) <> 0 THEN
-
-- Find middle name only
-
pname_out := substr(pname_out, instr(pname_out, '^', 1 ,2)+1, LENGTH(pname_out) - (instr(pname_out, '^', 1, 2) -1));
-
ELSE
-
-- Assume we only have no middle name
-
pname_out := NULL;
-
END IF;
-
-- return pname_out
-
RETURN (pname_out);
-
END;
-
/
-
-
--
-
-- Create COMBINENAMES -- Function Will combine name components into a formated
-
-- DICOM patient name
-
--
-
prompt Creating COMBINENAMES function
-
CREATE OR REPLACE FUNCTION COMBINENAMES(p_last IN VARCHAR2, p_first VARCHAR2, p_middle VARCHAR2)
-
RETURN VARCHAR2
-
DETERMINISTIC
-
IS
-
pname_out VARCHAR2(64) := NULL; -- init p_nameout
-
theseperator VARCHAR2(1) := '^'; -- define the separator
-
v_name VARCHAR2(64) := NULL;
-
BEGIN
-
IF p_last IS NOT NULL THEN
-
v_name := p_last;
-
v_name := replace(v_name, ',', ' ');
-
pname_out := LTRIM(RTRIM(v_name));
-
IF pname_out IS NOT NULL THEN
-
IF p_first IS NOT NULL THEN
-
v_name := p_first;
-
v_name := replace(v_name, ',', ' ');
-
pname_out := pname_out || theseperator || LTRIM(RTRIM(v_name));
-
IF p_middle IS NOT NULL THEN
-
v_name := p_middle;
-
v_name := replace(v_name, ',', ' ');
-
pname_out := pname_out || theseperator || LTRIM(RTRIM(v_name));
-
END IF;
-
END IF;
-
END IF;
-
END IF;
-
-- return pname_out
-
RETURN (pname_out);
-
END;
-
/
-
-
--
-
-- Create COMBINEDATETIME -- Function Will convert a date and time field into
-
-- a single date field;
-
--
-
prompt Creating COMBINEDATETIME function
-
CREATE OR REPLACE FUNCTION COMBINEDATETIME(DATEFIELD IN DATE, TIMEFIELD IN DATE)
-
RETURN DATE
-
DETERMINISTIC
-
IS
-
date_out DATE;
-
strDate VARCHAR2(10);
-
strTime VARCHAR2(10);
-
BEGIN
-
--
-
-- Create COMBINEDATETIME -- Function Will convert a date and time field into
-
-- a single date field;
-
--
-
-- get date
-
strdate:= to_char(DATEFIELD, 'YYYYMMDD');
-
-- get time
-
strtime:= to_char(TIMEFIELD, 'HH24:MI:SS');
-
-- Combine
-
date_out:= to_date(CONCAT(strdate,strtime), 'YYYYMMDDHH24:MI:SS');
-
-- Return
-
RETURN(date_out);
-
END;
-
/
-
-
--
-
-- Convert2DigitDate -- Function should convert date with 2 digit year.
-
--
-
-- Accepted date formats:
-
-- MM/DD/YY
-
-- MM/DD/YYYY
-
--
-
-- For 2 digit year dates:
-
-- Assume 2000's for dates <= '07 and assume
-
-- 1900's for dates > '07.
-
--
-
-- Updated by JT on 03/02/2007
-
--
-
prompt Creating Convert2DigitDate function
-
CREATE OR REPLACE FUNCTION Convert2DigitDate(date_in IN VARCHAR2)
-
RETURN DATE
-
DETERMINISTIC
-
IS
-
date_str VARCHAR2(64);
-
year_str VARCHAR2(64);
-
date_out DATE;
-
BEGIN
-
--
-
-- Convert2DigitDate -- Function should convert date with 2 digit year.
-
--
-
-- Accepted date formats:
-
-- MM/DD/YY
-
-- MM/DD/YYYY
-
--
-
-- For 2 digit year dates:
-
-- Assume 2000's for dates <= '07 and assume
-
-- 1900's for dates > '07.
-
--
-
-- Check whether the date is already in 'MM/DD/YYYY' format
-
IF
-
length(date_in) = 10 AND
-
substr(date_in, 3, 1) = '/' AND
-
substr(date_in, 6, 1) = '/' AND
-
IsNumeric(substr(date_in, 7, 4)) = TRUE
-
THEN
-
--if date is already in 'MM/DD/YYYY' format, then covert it.
-
date_out := to_date_null(date_in, 'MM/DD/YYYY');
-
-
-- Check for date in 'MM/DD/YY' format
-
ELSIF
-
length(date_in) = 8 AND
-
substr(date_in, 3, 1) = '/' AND
-
substr(date_in, 6, 1) = '/' AND
-
IsNumeric(substr(date_in, 7, 2)) = TRUE
-
THEN
-
-- Process date with 2 digit year
-
-- transfer first part of date string
-
date_str := substr(date_in, 1, 5);
-
-- Get year string from orig date
-
year_str := substr(date_in, 7, 2);
-
-- Add 2 digits to the year part of the string (making 4 digit)
-
IF to_number(year_str) <= 7 THEN
-
-- If the year is less or equal to '07, then assume 2000's
-
year_str := '20' || year_str;
-
ELSE
-
-- If the year is greater than '07, assume 1900's
-
year_str := '19' || year_str;
-
END IF;
-
-- Put whole date back together
-
date_str := date_str || year_str;
-
-- Convert date string to date
-
date_out := to_date_null(date_str, 'MM/DD/YYYY');
-
-
-- Handle all other date formats by returning null
-
ELSE
-
-- Invalid date format
-
date_out := null;
-
END IF;
-
-
-- Return our result
-
RETURN (date_out);
-
END;
-
/
-
-
So, Are you not able to test these scripts??
You can test them by calling the functions from an anonymous block or select statement itself.
One suggestion is if you are using IS_NUMERIC function in your project requirement then include "." (decimal) in your translate command along with the numbers becuase the number can have decimal places
Can you please help me with an example?
Thanks
Can you please help me with an example?
Thanks
Try this:
Note: Not Tested!! -
-
SELECT LASTNAME('BOND,JAMES') FROM DUAL;
-
-
-
-
SQL> SET SERVEROUTPUT ON
-
-
DECLARE
-
last_name VARCHAR2(20) := NULL;
-
BEGIN
-
last_name := LASTNAME('BOND,JAMES');
-
DBMS_OUTPUT.PUT_LINE(last_name);
-
END;
-
/
-
-
Hi, Thanks for your help. However,I want each test to either show that it pass or failed, how do I do that.
Hi, Thanks for your help. However,I want each test to either show that it pass or failed, how do I do that.
The output of your function will be the most important validation source for you. If your function gives you correct output then its working fine and it is passed else it is failed.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: TheDustbustr |
last post by:
I'm writing a game in C++ that calls out to Python for scripting. The C++
kernel holds an instance of ScriptCtl and calls the load(filename) method to
load a script, then run() to run all loaded scripts.
<code>
class ScriptCtl:
threads=
def load(self, filename):
|
by: Ian Giblin |
last post by:
I am an experienced C programmer, learning C++ by writinging a
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.
Currently I have a portable "ScriptSession" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script...
|
by: cwdjrxyz |
last post by:
Javascript has a very small math function list. However there is no
reason that this list can not be extended greatly. Speed is not an
issue, unless you nest complicated calculations several levels deep. In
that case you need much more ram than a PC has to store functions
calculated in loops so that you do not have to recalculate every time
you cycle through the nest of loops. Using a HD for storage to extend
ram is much too slow for many...
|
by: Noah |
last post by:
I would like to package my main script and all the
modules it imports into a single script that will
run just as the collection would. It should not
need to package standard Python lib modules -- just
my local modules. This is not the same question
that would be answered with py2exe or py2app. I
don't need to package the script into a binary
along with Python. I expect Python to be installed.
I also don't want to use distutils to install...
|
by: Sakcee |
last post by:
Hi
I am trying to use pyUnit to create a framework for testing functions
I am reading function name, expected output, from a text file.
and in python generating dynamic test functions
something like this
class getUsStatesTest( unittest.TestCase ):
| |
by: sylcheung |
last post by:
Is it possible to use python to unit test C++ code? If yes, is there
any example available?
Thank you.
|
by: steven.harms |
last post by:
Hi gurus,
1. foo.html has a script tag to reference'foo.js'
2. foo.js wants to use the handy datadumper.js routines
3. How does foo.js become aware of functions in the datadumper.js
namespace?
Is this possible? I'm sure it must be?
Assuming it is....
|
by: Martijn Saly |
last post by:
I'd like to test in my script, if it's going to be possible to enable
priviliges.
If I use this...
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
....it presents a dialog to the user asking if it's ok. Now I don't want
to hide that dialog, I'd like to know if it's going to be possible to
click the Allow button, before ever making this call. Basically I need
|
by: Alan Isaac |
last post by:
This is really a repackaging of an earlier question,
probably illustrating that I still do not understand relative imports.
Suppose I have the package structure (taken from the example at
http://www.python.org/dev/peps/pep-0328/)
package/
__init__.py
subpackage1/
__init__.py
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |