Tests & implementation for distance computation