Optimization of test and maintenance intervals based on risk and cost