The Accuracy of the Center-of-Gravity Method for Measuring Velocity and Magnetic Field Strength in the Solar Photosphere