루비 함수가 여러 개인 경우 입력이 올바른지 입력이 올바른지 확인하고 싶습니다. 그것을 할 수있는 합리적인 방법은 무엇입니까? how to put assertions in ruby code :루비에서 함수 입력을 테스트하는 적절한 방법은 무엇입니까?
는 여기에 내가
# 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
내가 여기에 관련 질문을 찾아 확인하고 싶은 내가 가지고있는 기능과 무엇 하나의 예입니다. 이것이 루비의 함수 입력을 테스트하는 더 좋은 방법인가요?
'1.class'는 나를 떨게 만든다. 'Time.new.class'는 내가 비명을 지르고 headdesk하고 싶게 만든다. –
프로그램이 메서드 시그니처에 유효한 값을 전달하는 것을 신뢰하지 않는 이유는 무엇입니까? 오염 된 데이터를 다루지 않는 한 단원 테스트 또는 예외에 의존하십시오. –