Toad World® Forums

Test a return value as valid year number


I recently was asked this question:

How do I set up a test so that it is a success if it returns any ‘date year’? For example any of these are legit results: 1980, 1200, 1990, 2009.

I tried setting up the expression’9999’ - to ensure it would be 4 digits, but it acts as though I wanted to test against the literal value 9999. The result says “value of 1994<> expected value 9999”.


There are several ways to do this. First, though, there is no built-in (to Code Tester) test for “valid year number” - though I can certainly look to adding that as a test for a string or numeric type…or even making the tool extensible to let you define tests like this. Hmmm. I will give that some thought - that sounds like fun.

In the meantime, though, any of these are possible:

  1. Create a function within the test definition that handles all the logic regarding what constitutes a valid year number. Then call that function in an expression test, as in:

function valid_year (year_in in number) return boolean
if year_in between 1000 and 9999
return true;
return false;
end if;

and then define a Boolean Expression test as follows:

valid_year (Q##function_return_value)

That funny looking string (“Q##function_return_value”) is the name of the variable populated with the function return value. How do I know that? The Properties Window of the default outcome created for me for the function return value shows that as the variable name.

  1. You could also create two outcomes for the function return value or OUT argument, one that checks to see if the number is > 1000 and another that it is less than 9999 - or whatever your rule is for validating a year number.

  2. You could also use date conversion functions to validate the number.