generator implementation and unittest