They don't lol, these tests don't just look at your DNA do they, they have access to all the genealogical records as well you know?
So, think about it, if your DNA matches with someone and their family tree goes back to the 1600's or whenever, this suggests that the person is one of your ancestors also.