Test cost function.