#!/usr/bin/python

from __future__ import print_function

import sys
import tlsh

def compute_hash(path):
    return tlsh.hash(open(path).read())

def compare_files(left_path, right_path):
    left_hash = compute_hash(left_path)
    right_hash = compute_hash(right_path)
    return tlsh.diff(left_hash, right_hash)

def main():
    score = compare_files('debian/tests/data/file1', 'debian/tests/data/file1')
    print('Identical:', score)
    if score != 0:
        raise Exception('Should be identical')
    score = compare_files('debian/tests/data/file1', 'debian/tests/data/file2')
    print('Similar:', score)
    if score >= 40:
        raise Exception('Should be similar')
    score = compare_files('debian/tests/data/file1', 'debian/tests/data/quick')
    print('Different:', score)
    if score <= 300:
        raise Exception('Should be different')

if __name__ == '__main__':
    main()
