public void testNoRefreshAfterFileUpdate() { ItemSimilarity similarity = new FileItemSimilarity(testFile, 0L); /// call a method to make sure the original file is loaded similarity.itemSimilarity(1L, 5L); /// change the underlying file, /// we have to wait at least a second to see the change in the file's lastModified timestamp Thread.sleep(2000L); writeLines(testFile, changedData); /// we shouldn't see any changes in the data as we have not yet refreshed Assert.AreEqual(0.5, similarity.itemSimilarity(1L, 7L), EPSILON); Assert.AreEqual(0.5, similarity.itemSimilarity(7L, 1L), EPSILON); Assert.True(Double.IsNaN(similarity.itemSimilarity(7L, 8L))); }
public void testLoadFromFile() { ItemSimilarity similarity = new FileItemSimilarity(testFile); Assert.AreEqual(0.125, similarity.itemSimilarity(1L, 5L), EPSILON); Assert.AreEqual(0.125, similarity.itemSimilarity(5L, 1L), EPSILON); Assert.AreEqual(0.5, similarity.itemSimilarity(1L, 7L), EPSILON); Assert.AreEqual(0.5, similarity.itemSimilarity(7L, 1L), EPSILON); Assert.True(Double.IsNaN(similarity.itemSimilarity(7L, 8L))); double[] valuesForOne = similarity.itemSimilarities(1L, new long[] { 5L, 7L }); Assert.NotNull(valuesForOne); Assert.AreEqual(2, valuesForOne.Length); Assert.AreEqual(0.125, valuesForOne[0], EPSILON); Assert.AreEqual(0.5, valuesForOne[1], EPSILON); }
public void testToString() { ItemSimilarity similarity = new FileItemSimilarity(testFile); Assert.True(!similarity.toString().isEmpty()); }