function testPer(img,imgName,len,m,n,typeDistance)

featureAll = zeros(0,0);
for i=1:len
    featureAll(i,:) = get_features(img{i},m,n);
end

%----- calculate the distance matrix------
for i=1:len
    for j=1:len
        disMatrix(i,j)=my_distance2(featureAll(i,:),featureAll(j,:),typeDistance);
    end
end

for i=1:len    
    currDist = disMatrix(i,:);
    currDist(i) = max(currDist);
    [currDistSort idx] = sort(currDist,'ascend');
    topFiveResult(i,:) = idx(1:5);
end


% output the top 5 to file
performance = zeros(30,1);
fid1 = fopen('top5_ResultName.txt','a');
fid2 = fopen('top5_ResultIdex.txt','a');
for i=1:len
    fprintf(fid1,'   %s: ',imgName{i});
    fprintf(fid2,'   %s: ',imgName{i});
    for j = 1:5
        fprintf(fid1,'%s   ',imgName{topFiveResult(i,j)});
        fprintf(fid2,'%d  ',topFiveResult(i,j));
    end
    fprintf(fid1,'\r\n');
    fprintf(fid2,'\r\n');
end
fprintf(fid1,'\r\n');
fprintf(fid2,'\r\n');
fclose(fid1);
fclose(fid2);

% output the performance to file
for i=1:len
    % 1--6
    if (i>0)&&(i<7)
        class1Num = find(topFiveResult(i,:)>0 & topFiveResult(i,:)<7);
        performance(i) = length(class1Num);
    end
    
    % 7-12
    if (i>6)&&(i<13)
        class2Num = find(topFiveResult(i,:)>6 & topFiveResult(i,:)<13);
        performance(i) = length(class2Num);
    end
    
    % 13-18
    if (i>12)&&(i<19)
        class3Num = find(topFiveResult(i,:)>12 & topFiveResult(i,:)<19);
        performance(i) = length(class3Num);
    end
    
    % 19-24
    if (i>18)&&(i<25)
        class4Num = find(topFiveResult(i,:)>18 & topFiveResult(i,:)<25);
        performance(i) = length(class4Num);
    end
    
    %25-30
    if (i>26)&&(i<31)
        class5Num = find(topFiveResult(i,:)>26 & topFiveResult(i,:)<31);
        performance(i) = length(class5Num);
    end
end


%-----output the statistic value of accuracy--------
fid = fopen('performance.txt','a');
errorNum = length(find(performance==0));
fprintf(fid,'   sum of correct = %d ',sum(performance));
fprintf(fid,'\r\n');
fclose(fid);
