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());
}
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;
}
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);
}
}
Aggregations