Pregnancy test

When is a pregnancy test accurate? How many days after sex can I take one? If I took one a little over 3 weeks after I had sex and it was negative is that pretty accurate?