I agree with this 100% and do the same thing.
If you need something that measures my ability, then go to my github page and go over the copious amounts of projects I have there and determine if my skill level is what you need for your company.
I had one interview where I had sent over a link to my github page. As soon as I sat down, I was given a large packet (it was about 20 pages) and asked to look at the code and figure out the bugs. Most of these were in Java and .Net. I reiterated I didn't work with either language and they told me to "just look at the examples and give it a try." I asked them if they had looked at my github page and reminded them I'm a front end developer. After they said, "Uhhh no, we didn't look at your examples." I stood up and told them, "Thank you gentlemen, but this interview is over. Thanks for wasting my time." and walked out.
I've also turned down "code challenges" that would eat up a week or so of my time. I've got a myriad of recruiters calling me for gigs, why would I waste a week working for free on your "code challenge"? I guess I'm at a point in my career where my work can speak for itself. I don't need to jump through a bunch of hoops to prove my abilities anymore.
The candidate can demonstrate their work and be assured that neither does the company extort free labour from them nor is the work they do for the bin, whereas the companies can see how they behave in real-world environments.
(Actually, would you mind if I stole this idea?)
Principles and self respect have real costs. The milieu right now is a race to the bottom, and refusing to be a part of it might get you left behind.
This is further evidence of the need for unions to make a comeback.
Self respect can't feed you, but it's not so bad.
Also, that HR person is not a trained doctor. They have no business administering any kind of test of this type, and certainly have no business trying to interpret the results. It is just woo nonsense. Might as well try to do handwriting analysis, or read my tea leaves.
You are not allowed (in the states) to ask interview questions about health. Yet, somehow, the courts have found these 'personality' tests legal. I don't understand, but I will not participate. I don't take drugs, but I won't take a pee test either.*
* these results might vary depending on how close I am to foreclosure and how low my saving are. Principles are costly.
But it doesn't only happen in this industry: my niece is a graphic designer & has been asked to provide samples of her work on projects ... to the interviewer's specification. She's done it, because she really needed the work, but felt terribly taken advantage of, and I'd agree: it's predatory.
I have the luxury of telling people that, no, I won't take their 1) IQ test, 2) Personality Test, or 3) their Coding Challenges. Not everybody does, certainly.
The appropriate thing to do is to either state up front that you'd need to be compensated for your time, or acknowledge that you're giving away work as a way to possibly get in the door & just write the best solution you can write - not leaving it incomplete, necessarily, either, as that is a sort-of halfway position that makes you look bad.