Java tutorial
// Acoustid -- Audio fingerprint lookup server // Copyright (C) 2010 Lukas Lalinsky // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. package org.acoustid.util; import java.io.IOException; import junit.framework.TestCase; import org.apache.commons.lang.ArrayUtils; public class FingerprintDecompressorTest extends TestCase { public void testOneItemOneBit() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 1 }; byte[] data = { 0, 0, 0, 1, 1 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testOneItemThreeBits() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 7 }; byte[] data = { 0, 0, 0, 1, 73, 0 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testOneItemOneBitExcept() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 1 << 6 }; byte[] data = { 0, 0, 0, 1, 7, 0 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testOneItemOneBitExcept2() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 1 << 8 }; byte[] data = { 0, 0, 0, 1, 7, 2 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testTwoItems() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 1, 0 }; byte[] data = { 0, 0, 0, 2, 65, 0 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testTwoItemsNoChange() throws IOException, IncompatibleFingerprintVersion { int[] expected = { 1, 1 }; byte[] data = { 0, 0, 0, 2, 1, 0 }; assertEquals(ArrayUtils.toString(expected), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } public void testDecompressCompressed() throws IOException, IncompatibleFingerprintVersion { int[] fingerprint = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; byte[] data = FingerprintCompressor.compress(fingerprint); assertEquals(ArrayUtils.toString(fingerprint), ArrayUtils.toString(FingerprintDecompressor.decompress(data))); } }