Updated os description logic to keep equals ignore match with guest os display name

This commit is contained in:
Harikrishna Patnala 2020-12-22 19:05:45 +05:30
parent c1a9f414a7
commit 4b8adeb5f0
2 changed files with 1 additions and 57 deletions

View File

@ -124,7 +124,7 @@ public class StringUtils {
/**
* Converts a List of tags to a comma separated list
* @param tagsList
* @param tags
* @return String containing a comma separated list of tags
*/
@ -313,30 +313,4 @@ public class StringUtils {
public static String toCSVList(final List<String> csvList) {
return join(csvList, ",");
}
/**
* Calculates minimum number of edits required to convert from one string to another string.
* @param str1 String that needs editing
* @param str2 Target string that is required/expected after editing
* @return minimum number of edits required to convert str1 to str2
*/
public static int minimumEditDistance(String str1, String str2) {
int str1Length = str1.length();
int str2Length = str2.length();
int[][] auxiliaryArray = new int[str1Length + 1][str2Length + 1];
for (int i = 0; i <= str1Length; i++) {
for (int j = 0; j <= str2Length; j++) {
if (i == 0)
auxiliaryArray[i][j] = j;
else if (j == 0)
auxiliaryArray[i][j] = i;
else if (str1.charAt(i - 1) == str2.charAt(j - 1))
auxiliaryArray[i][j] = auxiliaryArray[i - 1][j - 1];
else
auxiliaryArray[i][j] = 1 + Integer.min(Integer.min(auxiliaryArray[i][j - 1], auxiliaryArray[i - 1][j]), auxiliaryArray[i - 1][j - 1]);
}
}
return auxiliaryArray[str1Length][str2Length];
}
}

View File

@ -258,34 +258,4 @@ public class StringUtilsTest {
String output = StringUtils.toCSVList(Arrays.asList(input.split(",")));
assertTrue(input.equals(output));
}
@Test
public void testZeroEditDistance() {
String str1 = "Other 32-bit";
String str2 = "Other 32-bit";
int minDistance = StringUtils.minimumEditDistance(str1, str2);
assertEquals(minDistance, 0);
}
@Test
public void testBestMatchStringWithEditDistance() {
String str1 = "FreeBSD 11 (32bit)";
String str2 = "FreeBSD 12 (64bit)";
String targetString = "FreeBSD 64bit";
int minDistanceStr1 = StringUtils.minimumEditDistance(str1, targetString);
int minDistanceStr2 = StringUtils.minimumEditDistance(str2, targetString);
// the best match will be str2, so expecting less edit distance
assertTrue(minDistanceStr2 < minDistanceStr1);
}
@Test
public void testCompletelyDifferentStringsWithEditDistance() {
String str1 = "Other (32-bit)";
String str2 = "SCO OpenServer 5";
String targetString = "Other 32-bit";
int minDistanceStr1 = StringUtils.minimumEditDistance(str1, targetString);
int minDistanceStr2 = StringUtils.minimumEditDistance(str2, targetString);
// the best match will be str1, so expecting less edit distance
assertTrue(minDistanceStr1 < minDistanceStr2);
}
}