IANAL, but as far as I understand it, the theory is that you commit copyright infringement if you copy, that is, you don't come up with the code by yourself (whether you type it or use a copying tool is irrelevant).
How the courts go about deciding whether you actually copied is tricky; it involves actual evidence (emails, testimonial, etc) and common sense, often in the form of expert opinions (you probably didn't just happen to write a 30 kLOC library that implements everything the same way, with just different variable names).
Now, there is a threshold of originality, that is, if there's only obvious way to write something, it shouldn't be infringing. But considering that rangeCheck() was considered to be infringing (see Oracle v. Google), I'm not sure we can depend on that. Then again, the guy did testify he actually copied it.
How the courts go about deciding whether you actually copied is tricky; it involves actual evidence (emails, testimonial, etc) and common sense, often in the form of expert opinions (you probably didn't just happen to write a 30 kLOC library that implements everything the same way, with just different variable names).
Now, there is a threshold of originality, that is, if there's only obvious way to write something, it shouldn't be infringing. But considering that rangeCheck() was considered to be infringing (see Oracle v. Google), I'm not sure we can depend on that. Then again, the guy did testify he actually copied it.