T-Cal: An optimal test for the calibration of predictive models