I'm a little surprised this works, given that the preprocessor doesn't deal in C++-isms like `true`.
My suggestion is that you put just the code you want on your reference sheet in one file, and then #include it from another file which does the testing. That way you can use LaTeX to generate the reference sheet by directly including the algorithm files, without having to copy-and-paste.