Search in sources :

Example 1 with NumberReader

use of func.lib.NumberReader in project mkgmap by openstreetmap.

the class NumberPreparerTest method testKnownStream.

/**
 * Just test that the test infrastructure is working with a known byte stream, this
 * is testing the tests.
 */
@Test
public void testKnownStream() {
    byte[] buf = { 0x41, 0x13, 0x27, 0x49, 0x60 };
    BitReader br = new BitReader(buf);
    NumberReader nr = new NumberReader(br);
    nr.setNumberOfNodes(1);
    List<Numbers> numbers = nr.readNumbers(true);
    assertEquals(1, numbers.size());
    assertEquals("0,E,24,8,O,23,13", numbers.get(0).toString());
}
Also used : NumberReader(func.lib.NumberReader) BitReader(uk.me.parabola.imgfmt.app.BitReader) Test(org.junit.Test)

Example 2 with NumberReader

use of func.lib.NumberReader in project mkgmap by openstreetmap.

the class NumberPreparerTest method writeAndRead.

private List<Numbers> writeAndRead(List<Numbers> numbers) {
    NumberPreparer preparer = new NumberPreparer(numbers);
    BitWriter bw = preparer.fetchBitStream();
    bytesUsed += bw.getLength();
    assertTrue("check valid flag", preparer.isValid());
    boolean swapped = preparer.getSwapped();
    // Now read it all back in again
    byte[] b1 = bw.getBytes();
    byte[] bytes = new byte[bw.getLength()];
    System.arraycopy(b1, 0, bytes, 0, bw.getLength());
    BitReader br = new BitReader(bytes);
    NumberReader nr = new NumberReader(br);
    nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
    List<Numbers> list = nr.readNumbers(swapped);
    for (Numbers n : list) n.setNodeNumber(n.getIndex());
    return list;
}
Also used : BitWriter(uk.me.parabola.imgfmt.app.BitWriter) NumberReader(func.lib.NumberReader) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Example 3 with NumberReader

use of func.lib.NumberReader in project mkgmap by openstreetmap.

the class NumberRangeTest method run.

private void run(String[] strings) {
    List<Numbers> numbers = new ArrayList<Numbers>();
    for (String s : strings) {
        Numbers n = new Numbers(s);
        n.setIndex(n.getNodeNumber());
        numbers.add(n);
    }
    NumberPreparer np = new NumberPreparer(numbers);
    BitWriter bitWriter = np.fetchBitStream();
    bytesUsed += bitWriter.getLength();
    // Now read it back in
    byte[] bytes = new byte[bitWriter.getLength()];
    System.arraycopy(bitWriter.getBytes(), 0, bytes, 0, bytes.length);
    NumberReader nr = new NumberReader(new BitReader(bytes));
    nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
    List<Numbers> list = nr.readNumbers(np.getSwapped());
    // Have to fix up the node numbers
    for (Numbers n : list) {
        n.setNodeNumber(n.getIndex());
    }
    // Test that they are the same.
    String orig = numbers.toString();
    String calculated = list.toString();
    if (!orig.equals(calculated)) {
        System.out.printf("Fail: expecting: %s\n            Got: %s\n", orig, calculated);
    }
}
Also used : BitWriter(uk.me.parabola.imgfmt.app.BitWriter) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ArrayList(java.util.ArrayList) NumberReader(func.lib.NumberReader) NumberPreparer(uk.me.parabola.imgfmt.app.net.NumberPreparer) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Aggregations

NumberReader (func.lib.NumberReader)3 BitReader (uk.me.parabola.imgfmt.app.BitReader)3 BitWriter (uk.me.parabola.imgfmt.app.BitWriter)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 NumberPreparer (uk.me.parabola.imgfmt.app.net.NumberPreparer)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1