unit test for cost function