In what way do you think this is wrong?

There are two possibilities: the normalisation, that only the first points are valid.

Or is the problem something else?

(you will find the equations are simpler if you use indices running from 0 to N-1)

You may also find it advantageous to use an interval 0-2 for x in the DFT to capture the spectral influence of the discontinuities better - if that makes any sense (consider the case where f(x)=1 for x in (0,1) and 0 otherwise).

CB