Verifying the result from lowpass filter
To eliminate gravity you need a high pass filter. From your source

This can be achieved by applying a high-pass filter. Conversely, a low-pass filter can be used to isolate the force of gravity.

You implemented a low pass filter. Instead try
$$G[n] = p \cdot G[n-1] + 0.5 \cdot (1-p) \cdot (a[n]-a[n-1])$$
where p is the location of your pole. I would start with $p = 0.9$

And I'd like to know how to verify the result.

Same you should do with any algorithm

Write down the math of the algorithm
Select some suitable test signals where you can pre-calculated the result
Run the test signals through your implementation and check whether the results match.
Verify all other quantitative requirements

So in your case, you should run a constant signal through and check whether the output is zero and you should run a sine wave at different frequencies to it and verify that the output is indeed a sine wave at the same frequency and that the gain at the corner frequency is $\sqrt{1/2}$