Edit distance calculation function and test program