Sharp Bounds for Generalized Uniformity Testing