A generalization of Fisher's exact test