Exemplo n.º 1
0
  @Test
  public void testLinearDependance() {

    byte[] segment = new byte[1000];

    new Random().nextBytes(segment);

    Decoder decoder = createDecoder(segment.length, 10);

    byte[] packet = new byte[10 + segment.length / 10];

    Encoder encoder = createEncoder(segment, 0, segment.length, 10);

    encoder.getPacket(packet, 0);

    decoder.addPacket(packet, 0);

    decoder.addPacket(packet, 0);

    assertEquals(1, decoder.getRank());

    while (!decoder.isDecoded()) {
      byte[] packet2 = new byte[10 + segment.length / 10];

      encoder.getPacket(packet2, 0);

      decoder.addPacket(packet2, 0);
    }

    byte[] decodedSegment = new byte[segment.length];

    decoder.getSegment(decodedSegment, 0);

    assertArrayEquals(segment, decodedSegment);
  }
Exemplo n.º 2
0
  @Test
  public void testOnlineCoding() {

    byte[] segment = new byte[1000];

    new Random().nextBytes(segment);

    Decoder decoder = createDecoder(segment.length, 20);

    Decoder decoder2 = createDecoder(segment.length, 20);

    Encoder encoder = createEncoder(segment, 0, segment.length, 20);

    while (!decoder.isDecoded()) {

      byte[] packet = new byte[segment.length / 20 + 20];

      encoder.getPacket(packet, 0);

      int prevRank = decoder.getRank();

      decoder.addPacket(packet, 0);

      if (prevRank < decoder.getRank()) {
        prevRank = decoder2.getRank();
        while (decoder2.getRank() == prevRank) {
          byte[] packet2 = new byte[segment.length / 20 + 20];
          decoder.getPacket(packet2, 0);
          decoder2.addPacket(packet2, 0);
        }
      }
    }

    byte[] segmentDecoded = new byte[segment.length];

    decoder.getSegment(segmentDecoded, 0);
    assertArrayEquals(segment, segmentDecoded);

    decoder2.getSegment(segmentDecoded, 0);
    assertArrayEquals(segment, segmentDecoded);
  }