Документация
HTML CSS PHP PERL другое

Section 17.10.  Exercise

 
Previous
Table of Contents
Next

17.10. Exercise

You can find the answer to this exercise in "Answer for Chapter 17" in the Appendix.

17.10.1. Exercise [60 min]

Write a module distribution, starting from the tests first.

Your goal is to create a module My::List::Util that exports two routines on request: sum( ) and shuffle( ). The sum( ) routine takes a list of values and returns the numeric sum. The shuffle( ) routine takes a list of values and randomly shuffles the ordering, returning the list.

Start with sum( ). Write the tests, and then add the code. You'll know you're done when the tests pass. Now include tests for shuffle, and then add the implementation for shuffle. You might peek in the perlfaq to find a shuffle( ) implementation.

Be sure to update the documentation and MANIFEST file as you go along.

If you can pair up with someone on this exercise, even better. One person writes the test for sum( ) and the implementation code for shuffle( ), and the other does the opposite. Swap the t/* files, and see if you can locate any errors!


Previous
Table of Contents
Next
© 2000- NIV