@Test
public void testMaxSimilaritiesPerItem() throws Exception {

  File inputFile = getTestTempFile("prefsForMaxSimilarities.txt");
  File outputDir = getTestTempDir("output");
  outputDir.delete();
  File tmpDir = getTestTempDir("tmp");
  writeLines(inputFile,
      "1,1,1",
      "1,3,1",
      "2,2,1",
      "2,3,1",
      "3,1,1",
      "3,2,1",
      "4,1,1",
      "4,2,1",
      "4,3,1",
      "5,2,1",
      "6,1,1",
      "6,2,1");
  ItemSimilarityJob similarityJob =  new ItemSimilarityJob();
  Configuration conf = new Configuration();
  conf.set("mapred.input.dir", inputFile.getAbsolutePath());
  conf.set("mapred.output.dir", outputDir.getAbsolutePath());
  conf.setBoolean("mapred.output.compress", false);
  similarityJob.setConf(conf);
  similarityJob.run(new String[] { "--tempDir", tmpDir.getAbsolutePath(), "--similarityClassname",
      TanimotoCoefficientSimilarity.class.getName(), "--maxSimilaritiesPerItem", "1" });
  File outPart = outputDir.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
      return name.startsWith("part-");
    }
  })[0];
  BufferedReader reader = Files.newReader(outPart, Charsets.UTF_8);
  String line;
  int currentLine = 1;
  while ((line = reader.readLine()) != null) {
    String[] tokens = TAB.split(line);
    long itemAID = Long.parseLong(tokens[0]);
    long itemBID = Long.parseLong(tokens[1]);
    double similarity = Double.parseDouble(tokens[2]);
    if (currentLine == 1) {
      assertEquals(1L, itemAID);
      assertEquals(2L, itemBID);
      assertEquals(0.5, similarity, 0.0001);
    }
    if (currentLine == 2) {
      assertEquals(1L, itemAID);
      assertEquals(3L, itemBID);
      assertEquals(0.4, similarity, 0.0001);
    }
    currentLine++;
  }
  int linesWritten = currentLine - 1;
  assertEquals(2, linesWritten);
}