Improve gradient test