函数要求:
In this exercise, you’ll validate that an address ends with a zip code.
Create a function named isValidZipCode(address,error):
- The address is passed as input to the first parameter
- If address ends in 5 numeric characters, set error to “” and quit with 1
- Otherwise, set error to a reasonable error message, and quit with 0
测试用例
1 - Valid address: "12345"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH(12345,.error)
*result has been incorrectly set to 0 but expected 1
2 - Valid address: "ABC 12345"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC 12345",.error)
*result has been incorrectly set to 0 but expected 1
3 - Valid address: "ABC,12345"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC,12345",.error)
*result has been incorrectly set to 0 but expected 1
4 - Valid address: "ABC,02345"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC,02345",.error)
*result has been incorrectly set to 0 but expected 1
5 - Valid address: "ABC 02345"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC 02345",.error)
*result has been incorrectly set to 0 but expected 1
6 - Invalid address: "ABC12"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC12",.error)
*result has been incorrectly set to 1 but expected 0
7 - Invalid address: "ABC 123A"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC 123A",.error)
*result has been incorrectly set to 1 but expected 0
8 - Invalid address: "ABC,1234"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC,1234",.error)
*result has been incorrectly set to 1 but expected 0
9 - Invalid address: "ABC,0234"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC,0234",.error)
*result has been incorrectly set to 1 but expected 0
10 - Invalid address: "ABC 0234"
*Test: s result=$$isValidZipCode^XCHR310EX1YCH("ABC 0234",.error)
*result has been incorrectly set to 1 but expected 0
源代码
R !,"Enter Zip:", address
D isValidZipCode(address)
Q
isValidZipCode(address,error)
I address'?5N
S error="error zip code" q 1
E
S error="" q 0