generalize test function