Test terminal recursive function