Updating code and tests.

Thanks for writing all the tests cases, especially the boundary conditions.

I've updated the agrad functions to pass through to the underlying library calls, which is contrary to what I told you. My fault. Anyway, it's been fixed.

After you've reviewed it, please merge. That will update the pull request to stan-dev and we'll merge it when it passes tests there.