package com.k13n.lt_codes;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

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

/**
 * Unit test for simple App.
 */
public class AppTest
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp() throws Exception
    {
        assertWorksWithPerfectChannel();
        assertTrue( true );
    }

    private void assertWorksWithPerfectChannel() throws Exception {
      InputStream is = getClass().getResourceAsStream("/test.txt");
      URL url = this.getClass().getResource("/test.txt");
      assertNotNull(url);
      File file = new File(url.getFile());

      byte[] data = new byte[(int)file.length()];
      DataInputStream s = new DataInputStream(is);
      s.readFully(data);
      s.close();

      int packetSize = 100;
      Encoder enc = new Encoder(data, packetSize);
      final Decoder dec = new Decoder(enc.getNPackets(), packetSize);

      enc.encode(new Encoder.Callback(){
        public boolean call(Encoder encoder, int[] neighbours, byte data[]) {
          return dec.receive(data, neighbours);
        }
      });

      dec.write(new FileOutputStream("/tmp/test.txt.out"));

      //assertFilesEqual("text.txt", "text.txt.out")
    }
}

@@ -802,16 +802,52 @@
 ption %7B%0A
+      String filename = %22test.txt%22;%0A
       In
@@ -894,25 +894,28 @@
 tream(%22/
-test.txt%22
+%22 + filename
 );%0A     
@@ -955,25 +955,28 @@
 ource(%22/
-test.txt%22
+%22 + filename
 );%0A     
@@ -1565,24 +1565,32 @@
 m(%22/tmp/
-test.txt
+%22 + filename + %22
 .out%22));

Modify the AppTest to work with the modified Decoder