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:
- 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
and then define a Boolean Expression test as follows:
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.
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.
You could also use date conversion functions to validate the number.