Add tests for gradient calculation.