refactor(test): use the built-in max/min to simplify the code (#4576)