|
home—lects—hws
D2L—breeze (snow day)
Due 2017.Sep.2225 (Mon) 11:00
Submit on D2L, and hardcopy:
utils.php,
utils-test.php,
silly.php.
(You can also provide a css file, if separate.)
(Bring hardcopy to Monday's class, or Friday's if you've finished it.)
(5pts) Write a function
We'll use this function to make our testing more convenient.
For example, your tests from
hw01
could be replaced with lines like “
Optional (for slight extra credit):
These further features make
Note that rectifying whitespace is particularly helpful
when you are comparing test-cases-written-on-a-Windows-system
(where a
newline uses two bytes),
and then running the code on php.radford.edu (a UNIX machine, where
any newlines are one byte).
(Alternately, you can also run
Put this function into utils.php -- it is a utility function-definition. It doesn't go in utils-test.php. because it is not itself testing anything (it's a function that your unit-tests will call to help them do their job!)
For example,
given an array with
For full credit, this function should involve a call to
For all assignments in this class (and all your classes, as appropriate):
You do not need to check for invalid-inputs to your functions. E.g.: if I ask for a function taking in (say) a number and a string, and you repeat in your function-comment that your function handles a number and a string, then you don't need to check for being given incorrect inputs — that's the caller's problem, not yours. Similarly for more refined types like "non-empty-string" or "integer in the range [1,12]": if it's in the comments as a pre-condition, that'll suffice.3
(We'll talk about validating input received from the (external, untrusted) user later.)
function foo( $someNum ) { // optional error-check: if !(is_numeric($someNum)) { throw new InvalidArgumentException( 'foo: expected number, given ' . $someNum ); } // ...now put your real code, uncluttered by further type-checks. } |
home—lects—hws
D2L—breeze (snow day)
©2017, Ian Barland, Radford University Last modified 2017.Sep.22 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |