source: Dev/trunk/src/client/dojox/encoding/tests/compression/splay.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.4 KB
Line 
1define(['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});
Note: See TracBrowser for help on using the repository browser.