### Question:
IdBasedCrossValidator implements CrossValidator { @Override public Iterator<Fold> iterator() { return new AbstractIterator2<Fold>() { int fold = 0; @Override protected Fold getNext() { if (fold < numFolds) { return new FoldImplementation(fold++); } return finished(); } }; } IdBasedCrossValidator(Dataset dataset, int numFolds, String idValueName);  IdBasedCrossValidator(Dataset dataset, String idValueName); @Override Iterator<Fold> iterator(); @Override int getNumFolds();  }### Answer:
@Test public void testCrossValidator() { Dataset data = new RandomDataset(100); IdBasedCrossValidator crossValidator = new IdBasedCrossValidator(data, 10, "index"); for (TrainTestSplit fold : crossValidator) { int trainSize = CollectionHelper.count(fold.getTrain().iterator()); int testSize = CollectionHelper.count(fold.getTest().iterator()); assertEquals(90, trainSize); assertEquals(10, testSize); Set<Instance> trainSet = CollectionHelper.newHashSet(fold.getTrain()); Set<Instance> testSet = CollectionHelper.newHashSet(fold.getTest()); trainSet.removeAll(testSet); testSet.removeAll(trainSet); assertEquals(90, trainSet.size()); assertEquals(10, testSet.size()); } }