Optimal Testing for Properties of Distributions