package innovimax.mixthem;

import innovimax.mixthem.MixThem;
import innovimax.mixthem.Constants;
import innovimax.mixthem.MixException;

import java.io.*;
import java.net.URL;

import org.junit.Assert;
import org.junit.Test;

/*
    Created by innovimax
    Generic tests for this application
*/
public class GenericTest {

   @Test
   public final void check1() throws MixException, FileNotFoundException, IOException {
          URL url1 = getClass().getResource("test001_file1.txt");
          URL url2 = getClass().getResource("test001_file2.txt");
          File file1 = new File(url1.getFile());
          File file2 = new File(url2.getFile());
          ByteArrayOutputStream baos_rule_1 = new ByteArrayOutputStream();
          MixThem.processFiles(Constants.RULE_1, file1, file2, baos_rule_1);
          Assert.assertTrue(checkFileEquals(file1, baos_rule_1.toByteArray()));
          ByteArrayOutputStream baos_rule_2 = new ByteArrayOutputStream();
          MixThem.processFiles(Constants.RULE_2, file1, file2, baos_rule_2);
          Assert.assertTrue(checkFileEquals(file2, baos_rule_2.toByteArray()));
    }
	
    private static boolean checkFileEquals(File fileExpected, byte[] result) throws FileNotFoundException, IOException {
       FileInputStream fisExpected = new FileInputStream(fileExpected);
       int c;
       int offset = 0;
       while ((c = fisExpected.read()) != -1) {
           if (offset >= result.length) return false;
           int d = result[offset++];
           if (c != d) return false;
       }
       if (offset > result.length) return false;
       return true;
    }

}

@@ -1117,16 +1117,713 @@
     %7D%0A%09%0A
+    @Test%0A    public final void checkRuleAltLine() throws MixException, FileNotFoundException, IOException %7B%0A        URL url1 = getClass().getResource(%22test001_file1.txt%22);%0A        URL url2 = getClass().getResource(%22test001_file2.txt%22);%0A        URL urlComp = getClass().getResource(%22test001_output-altline.txt%22);%0A        File file1 = new File(url1.getFile());%0A        File file2 = new File(url2.getFile());%0A        File fileComp = new File(urlComp.getFile());%0A        ByteArrayOutputStream baos_rule = new ByteArrayOutputStream();%0A        MixThem.processFiles(Constants.RULE_ALT_LINE, file1, file2, baos_rule);%0A        Assert.assertTrue(checkFileEquals(fileComp, baos_rule.toByteArray()));%0A    %7D%0A%0A
     priv

add gereric test for rule alt-line