add test code for examples shown in the documentation

this is to ensure that examples actually work
(first run test code, then copy/paste to documentation)