package org.deeplearning4j.datasets.iterator;

import org.canova.api.records.reader.RecordReader;
import org.canova.api.records.reader.impl.FileRecordReader;
import org.canova.api.split.FileSplit;
import org.deeplearning4j.datasets.canova.RecordReaderDataSetIterator;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.DataSet;

import java.io.File;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 */

public class MultipleEpochsIteratorTest {

    protected File file1, file2, file3, file4, newPath;
    protected static String localPath = System.getProperty("java.io.tmpdir") + File.separator;
    protected static String testPath = localPath + "test-folder" + File.separator;


    @Before
    @Ignore
    public void doBefore() throws IOException {
        newPath = new File(testPath);

        newPath.mkdir();

        file1 = File.createTempFile("myfile_1", ".jpg", newPath);
        file2 = File.createTempFile("myfile_2", ".txt", newPath);
        file3 = File.createTempFile("myfile_3", ".jpg", newPath);
        file4 = File.createTempFile("treehouse_4", ".jpg", newPath);
    }


    @Test
    public void testNextAndReset() throws Exception{
        int epochs = 2;
        int batchSize = 2;

        RecordReader recordReader = new FileRecordReader();
        recordReader.initialize(new FileSplit(new File(testPath)));
        DataSetIterator iter = new RecordReaderDataSetIterator(recordReader, batchSize);
        MultipleEpochsIterator multiIter = new MultipleEpochsIterator(epochs, iter);

        assertTrue(multiIter.hasNext());

        while(multiIter.hasNext()){
            DataSet path = multiIter.next();
            assertFalse(path == null);
        }
        assertEquals(epochs, multiIter.numPasses, 0.0);

    }


    @After
    @Ignore
    public void doAfter(){
        file1.delete();
        file2.delete();
        file3.delete();
        file4.delete();
        newPath.delete();
    }



}

@@ -83,32 +83,91 @@
 r.RecordReader;%0A
+import org.canova.api.records.reader.impl.CSVRecordReader;%0A
 import org.canov
@@ -249,16 +249,62 @@
 eSplit;%0A
+import org.canova.api.util.ClassPathResource;%0A
 import o
@@ -736,16 +736,8 @@
 e;%0A%0A
-/**%0A */%0A
 %0Apub
@@ -780,656 +780,8 @@
  %7B%0A%0A
-    protected File file1, file2, file3, file4, newPath;%0A    protected static String localPath = System.getProperty(%22java.io.tmpdir%22) + File.separator;%0A    protected static String testPath = localPath + %22test-folder%22 + File.separator;%0A%0A%0A    @Before%0A    @Ignore%0A    public void doBefore() throws IOException %7B%0A        newPath = new File(testPath);%0A%0A        newPath.mkdir();%0A%0A        file1 = File.createTempFile(%22myfile_1%22, %22.jpg%22, newPath);%0A        file2 = File.createTempFile(%22myfile_2%22, %22.txt%22, newPath);%0A        file3 = File.createTempFile(%22myfile_3%22, %22.jpg%22, newPath);%0A        file4 = File.createTempFile(%22treehouse_4%22, %22.jpg%22, newPath);%0A    %7D%0A%0A%0A
     
@@ -864,36 +864,9 @@
 s = 
-2;%0A        int batchSize = 2
+3
 ;%0A%0A 
@@ -890,26 +890,16 @@
 er r
-ecordReade
 r = new 
 File
@@ -894,20 +894,19 @@
 r = new 
-File
+CSV
 RecordRe
@@ -922,26 +922,16 @@
        r
-ecordReade
 r.initia
@@ -957,21 +957,46 @@
 new 
-File(testPath
+ClassPathResource(%22iris.txt%22).getFile(
 )));
@@ -1064,30 +1064,14 @@
 or(r
-ecordReader, batchSize
+r, 150
 );%0A 
@@ -1387,196 +1387,13 @@
 0);%0A
-%0A
     %7D%0A%0A
-%0A    @After%0A    @Ignore%0A    public void doAfter()%7B%0A        file1.delete();%0A        file2.delete();%0A        file3.delete();%0A        file4.delete();%0A        newPath.delete();%0A    %7D%0A%0A%0A%0A
 %7D%0A

Fix multiple epochs iterator test