|
Due 2018.Feb.01 in class
Submit on D2L, and hardcopy:
utils.php,
utils-test.php,
silly.php.
(You can also provide a css file, if separate.)
The file silly.php
should also be viewable on the web, as discussed below.
(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!)
Note: We are not creating HTML for an entire table — merely one row. (Though, we might make a bunch of calls to this function, and splice the results between the string “<table> ” and “</table> ” … and it might even be a another function with its own loop, that is making the calls toasRow .)
(2pts extra credit)
Add an optional second-parameter “
For example,
given an array with
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.4
(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. } |
This page licensed CC-BY 4.0 Ian Barland Page last generated 2018.Mar.21 (Wed) | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |