Sam's decision not to kill Gollum, though not the same kind of pity that Bilbo
and Frodo show him, is in a way a test. It is fortuitous, of course,
since it allows Gollum to survive so he can destroy the Ring. In that
sense, Sam's actions do ensure the fulfilment of the quest, albeit in an
indirect way. Sam does thwack at him with a big old stick, but under the
circumstances he could easily have killed Gollum (with the strength he seems to
have gain after wounding a
mega-spider).
************************
"All wizards should have a hobbit or two in their care..."