code for testing finite time optimum