Skip to content

Commit

Permalink
verify my understanding of the code
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1337444 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed May 12, 2012
1 parent 4cc0284 commit 020c03d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Expand Up @@ -1321,7 +1321,10 @@ static final class Data extends Object {
// ============

/**
* Index in fmap[] of original string after sorting.
* Index of original line in Burrows-Wheeler table.
*
* <p>This is the index in fmap that points to the last byte
* of the original data.</p>
*/
int origPtr;

Expand Down
@@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.compressors.bzip2;

import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class BlockSortTest {

private static final byte[] FIXTURE = { 0, 1, (byte) 252, (byte) 253, (byte) 255,
(byte) 254, 3, 2, (byte) 128 };

/*
Burrows-Wheeler transform of fixture the manual way:
* build the matrix
0, 1, 252, 253, 255, 254, 3, 2, 128
1, 252, 253, 255, 254, 3, 2, 128, 0
252, 253, 255, 254, 3, 2, 128, 0, 1
253, 255, 254, 3, 2, 128, 0, 1, 252
255, 254, 3, 2, 128, 0, 1, 252, 253
254, 3, 2, 128, 0, 1, 252, 253, 255
3, 2, 128, 0, 1, 252, 253, 255, 254
2, 128, 0, 1, 252, 253, 255, 254, 3
128, 0, 1, 252, 253, 255, 254, 3, 2
* sort it
0, 1, 252, 253, 255, 254, 3, 2, 128
1, 252, 253, 255, 254, 3, 2, 128, 0
2, 128, 0, 1, 252, 253, 255, 254, 3
3, 2, 128, 0, 1, 252, 253, 255, 254
128, 0, 1, 252, 253, 255, 254, 3, 2
252, 253, 255, 254, 3, 2, 128, 0, 1
253, 255, 254, 3, 2, 128, 0, 1, 252
254, 3, 2, 128, 0, 1, 252, 253, 255
255, 254, 3, 2, 128, 0, 1, 252, 253
* grab last column
128, 0, 3, 254, 2, 1, 252, 255, 253
and the original line has been 0
*/

private static final byte[] FIXTURE_BWT = { (byte) 128, 0, 3, (byte) 254, 2, 1,
(byte) 252, (byte) 255, (byte) 253 };

@Test
public void testSortFixture() {
BZip2CompressorOutputStream.Data data = new BZip2CompressorOutputStream.Data(1);
System.arraycopy(FIXTURE, 0, data.block, 1, FIXTURE.length);
BlockSort s = new BlockSort(data);
assertFalse(s.blockSort(data, FIXTURE.length - 1));
assertEquals(FIXTURE[FIXTURE.length - 1], data.block[0]);
for (int i = 0; i < FIXTURE.length; i++) {
assertEquals(FIXTURE_BWT[i], data.block[data.fmap[i]]);
}
assertEquals(0, data.origPtr);
}
}

0 comments on commit 020c03d

Please sign in to comment.