Debian Codegraph @

dojox/encoding/tests/compression/splay.js

raw symbols SCIP
1 define(['doh', '../../compression/splay', '../../bits'], function(doh, Splay, dcb){
2 var msg1 = "The rain in Spain falls mainly on the plain.";
3 var msg2 = "The rain in Spain falls mainly on the plain.1";
4 var msg3 = "The rain in Spain falls mainly on the plain.ab";
5 var msg4 = "The rain in Spain falls mainly on the plain.!@#";
6
7 var s2b = function(s){
8 var b = [];
9 for(var i = 0; i < s.length; ++i){
10 b.push(s.charCodeAt(i));
11 }
12 return b;
13 };
14
15 var b2s = function(b){
16 var s = [];
17 dojo.forEach(b, function(c){ s.push(String.fromCharCode(c)); });
18 return s.join("");
19 };
20
21 var encode = function(msg){
22 var x = new dcb.OutputStream(), encoder = new Splay(256);
23 dojo.forEach(s2b(msg), function(v){ encoder.encode(v, x); });
24 console.debug("bits =", x.getWidth());
25 return x.getBuffer();
26 };
27
28 var decode = function(n, buf){
29 var x = new dcb.InputStream(buf, buf.length * 8), decoder = new Splay(256), t = [];
30 for(var i = 0; i < n; ++i){ t.push(decoder.decode(x)); }
31 return b2s(t);
32 };
33
34 doh.register("dojox.encoding.tests.compression.splay", [
35 function testSplayMsg1(t){ t.assertEqual(msg1, decode(msg1.length, encode(msg1))); },
36 function testSplayMsg2(t){ t.assertEqual(msg2, decode(msg2.length, encode(msg2))); },
37 function testSplayMsg3(t){ t.assertEqual(msg3, decode(msg3.length, encode(msg3))); },
38 function testSplayMsg4(t){ t.assertEqual(msg4, decode(msg4.length, encode(msg4))); }
39 ]);
40 });