Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1035680 // Test_HuffmanByteArray

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (15640L/92K).

1  
sclass Test_HuffmanByteArray {
2  
  gettable HuffmanByteArray array;
3  
  gettable HuffmanByteArray restoredArray;
4  
  gettable byte[] compressed;
5  
  
6  
  void test(int... dataInts) {
7  
    byte[] data = convertIntArrayToByteArray(dataInts);
8  
    print("=============");
9  
    printWithIndent("DATA | ", spaceIfEmpty(hexDump(data)));
10  
    
11  
    array = new HuffmanByteArray(data);
12  
    compressed = array.toByteArray();
13  
    printWithIndent("COMP | ", hexDump(compressed));
14  
    
15  
    restoredArray = new HuffmanByteArray().fromByteArray(compressed);
16  
    printWithIndent("REST | ", spaceIfEmpty(hexDump(restoredArray!)));
17  
    assertByteArrayEquals(data, restoredArray!);
18  
    //printWithIndent(" OK  | ", spaceIfEmpty(hexDump(data)));
19  
  }
20  
  
21  
  run {
22  
    test(); // empty array
23  
    
24  
    // try every single byte
25  
    for (int i = 0; i < 256; i++)
26  
      test((byte) i);
27  
      
28  
    // try some longer patterns
29  
    test(0, 0);
30  
    test(0, 1);
31  
    test(0, 1, 2);
32  
    test(3, 3, 4, 5);
33  
  }
34  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035680
Snippet name: Test_HuffmanByteArray
Eternal ID of this version: #1035680/11
Text MD5: 50d1a5f882bb313b61d8e4bed7f24247
Transpilation MD5: eab25088c27201c91d5e5856a8156b45
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-06 20:54:26
Source code size: 994 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 193 / 339
Version history: 10 change(s)
Referenced in: [show references]