1 5 package org.h2.test.unit; 6 7 import java.util.Random ; 8 9 import org.h2.test.TestBase; 10 import org.h2.tools.CompressTool; 11 12 public class TestCompress extends TestBase { 13 14 public void test() throws Exception { 15 if(config.big) { 16 for(int i=0; i<100; i++) { 17 test(i); 18 } 19 for(int i=100; i<10000; i += (i+i+1)) { 20 test(i); 21 } 22 } else { 23 test(0); 24 test(1); 25 test(7); 26 test(50); 27 test(200); 28 } 29 } 30 31 void test(int len) throws Exception { 32 for(int pattern = 0; pattern < 3; pattern++) { 33 byte[] buff = new byte[len]; 34 switch(pattern) { 35 case 0: 36 break; 38 case 1: { 39 for(int x=0; x<len; x++) { 40 buff[x] = (byte)(x & 10); 41 } 42 break; 43 } 44 case 2: { 45 Random r = new Random (len); 46 r.nextBytes(buff); 47 break; 48 } 49 } 50 String [] algorithm= new String []{ 51 "LZF", "Deflate", "No" 52 }; 53 CompressTool utils = CompressTool.getInstance(); 54 for(int i=0; i<algorithm.length; i++) { 55 byte[] out = utils.compress(buff, algorithm[i]); 56 byte[] test = utils.expand(out); 57 check(test.length, buff.length); 58 check(buff, test); 59 } 60 } 61 } 62 63 } 64 | Popular Tags |