I have several ruby functions and want to check that the input is correct and also whether the input makes sense. What is a sensible way to do that?
Here's an example with one of the functions I have and what I would like to check
# Converts civil time to solar time
# civilT: Time object
# longitude: float
# timezone: fixnum
def to_solarT(civilT,longitude,timezone)
# pseudo code to check that input is correct
assert(civilT.class == Time.new(2013,1,1).class)
assert(longitude.class == 8.0.class)
assert(timezone.class == 1.class)
# More pseudocode to check if the inputs makes sense, in this case
# whether the given longitude and timezone inputs make sense or whether
# the timezone relates to say Fiji and the longitude to Scotland. Done
# using the imaginary 'longitude_in_timezone' function
assert(longitude_in_timezone(longitude,timezone))
end
I found a related question here: how to put assertions in ruby code. Is this the way to go or are there better ways to test function input in ruby?