|
Due 2019.Feb.12 (Tue) 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!)
Don’t Panic:As of Feb.08, I am suspecting that most of the class has not had their accoun configured so that php.radford.edu can see their H: drive. I've filed a ticket w/ Radford IT.
SO: make sure your permissions are correct, and that your silly.php runs from rucs’s command line, but DON’T PANIC if you can’t view the files via the web. (For grading, if it’s not fixed, I’ll write a script which simply looks at the file-permissions of your silly.php and each enclosing folder.)
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
We mentioned in lecture how PHP arrays are hash tables. We didn’t mention, though, how to loop over keys&values together. See the 2nd half of the video-in-lecture notes “arrays in php” (actual loop starts at 10m30s).
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 | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |