As I understand it, the torrent file contains a hash for each piece of the file you are downloading. It simply checks the hashes for each piece you think you have, against the checklist. Much like when you download a torrent, any piece that does not match is discarded.
In more detail, based off the bitorrent specifications (
http://www.bittorrent.org/beps/bep_0003.html ) you have your downloaded file, 'piece length' and 'pieces'. Piece length is the size of each piece, and pieces is simply the sha1 sum of each piece, appended to the previous piece to form a long string.
To simplify things, lets assume you preallocated the file, and you basically have a large 'padded' file of equal length to your source file. First, based off piece length, the program gets the first n bits of the file, and does a SHA1 sum. It then compares the SHA1 sum of the file to the corresponding part of 'pieces'. If they match, we're good. Else, its marked as no good and discarded.