QGram { public static double distance(int q, String str1,String str2){ return distance(q, Transformations.convertStringToIntArray(str1),Transformations.convertStringToIntArray(str2)); }  static int qGramCount(int q, int str[]); static int qGramCount(int q, int str1[], int str2[]); static double distance(int q, String str1,String str2); static double distance(int q, int str1[],int str2[]);  }
@Test public void test1(){ int q = 2; String str1 = "kitten"; String str2 = "sitting"; Asserts.assertGreaterThanZero(q); Asserts.validate(q<=str1.length(), "the q-gram (substring) length is greater than the string length"); Asserts.validate(q<=str2.length(), "the q-gram (substring) length is greater than the string length"); double res = QGram.distance(q,str1,str2); Asserts.assertEquals(res, 0.181818182); }
@Test public void test2(){ int q = 3; String str1 = "cooked"; String str2 = "cooking"; Asserts.assertGreaterThanZero(q); Asserts.validate(q<=str1.length(), "the q-gram (substring) length is greater than the string length"); Asserts.validate(q<=str2.length(), "the q-gram (substring) length is greater than the string length"); double res = QGram.distance(q,str1,str2); Asserts.assertEquals(res, 0.222222222); }
@Test public void test3(){ int q = 4; String str1 = "running"; String str2 = "swim"; Asserts.assertGreaterThanZero(q); Asserts.validate(q<=str1.length(), "the q-gram (substring) length is greater than the string length"); Asserts.validate(q<=str2.length(), "the q-gram (substring) length is greater than the string length"); double res = QGram.distance(q,str1,str2); Asserts.assertEquals(res, 1.2); }