/* Problem Name is &&& Dist. Between Strings &&& PLEASE DO NOT REMOVE THIS LINE. */
public class Solution {
/*
/**
Given two words returns the shortest distance between their two midpoints in number of characters
Words can appear multiple times in any order and should be case insensitive.
E.g. for the document="This is a sample document we just made up"
shortestDistance( document, "we", "just" ) == 4
shortestDistance( document, "is", "a" ) == 2.5
shortestDistance( document, "is", "not" ) == -1
*/
public static double shortestDistance(String document, String word1, String word2) {
}
public static boolean doTestsPass() {// todo: implement more tests if you'd like
return shortestDistance(DOCUMENT, "and", "graphic") == 6d &&
shortestDistance(DOCUMENT, "transfer", "it") == 14d &&
shortestDistance(DOCUMENT, "layout", "It" ) == 6d &&
shortestDistance(DOCUMENT, "Design", "filler" ) == 25d &&
shortestDistance(DOCUMENT, "It", "transfer") == 14d &&
Math.abs(shortestDistance(DOCUMENT, "of", "lorem") - 4.5) < 0.000001 &&
shortestDistance(DOCUMENT, "thiswordisnotthere", "lorem") == -1d;}
public static void main(String[] args) {
// Run the tests
if (doTestsPass()) {
System.out.println("All tests pass");
} else {
System.out.println("There are test failures");
}
}