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")
    }
}

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 {
      String filename = "test.txt";
      InputStream is = getClass().getResourceAsStream("/" + filename);
      URL url = this.getClass().getResource("/" + filename);
      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/" + filename + ".out"));

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

Modify the AppTest to work with the modified Decoder