Add a small function to calculate nearest even number

also refine the test case