How to use bytesToString method in wpt

Best JavaScript code snippet using wpt

util_unittest.js

Source:util_unittest.js Github

copy

Full Screen

...181 const GB = 2 ** 30;182 const TB = 2 ** 40;183 const PB = 2 ** 50;184 // Up to 1KB is displayed as 'bytes'.185 assertEquals(util.bytesToString(0), '0 bytes');186 assertEquals(util.bytesToString(10), '10 bytes');187 assertEquals(util.bytesToString(KB - 1), '1,023 bytes');188 assertEquals(util.bytesToString(KB), '1 KB');189 // Up to 1MB is displayed as a number of KBs with no precision digit.190 assertEquals(util.bytesToString(2 * KB), '2 KB');191 assertEquals(util.bytesToString(2 * KB + 1), '3 KB');192 assertEquals(util.bytesToString(MB - KB), '1,023 KB');193 assertEquals(util.bytesToString(MB - KB + 1), '1,024 KB');194 assertEquals(util.bytesToString(MB - 1), '1,024 KB');195 assertEquals(util.bytesToString(MB), '1 MB');196 // Up to 1GB is displayed as a number of MBs with <= 1 precision digit.197 assertEquals(util.bytesToString(2.55 * MB - 1), '2.5 MB');198 assertEquals(util.bytesToString(2.55 * MB), '2.6 MB');199 assertEquals(util.bytesToString(GB - 0.05 * MB - 1), '1,023.9 MB');200 assertEquals(util.bytesToString(GB - 0.05 * MB), '1,024 MB');201 assertEquals(util.bytesToString(GB - 1), '1,024 MB');202 assertEquals(util.bytesToString(GB), '1 GB');203 // Up to 1TB is displayed as a number of GBs with <= 1 precision digit.204 assertEquals(util.bytesToString(2.55 * GB - 1), '2.5 GB');205 assertEquals(util.bytesToString(2.55 * GB), '2.6 GB');206 assertEquals(util.bytesToString(TB - 0.05 * GB - 1), '1,023.9 GB');207 assertEquals(util.bytesToString(TB - 0.05 * GB), '1,024 GB');208 assertEquals(util.bytesToString(TB - 1), '1,024 GB');209 assertEquals(util.bytesToString(TB), '1 TB');210 // Up to 1PB is displayed as a number of TBs with <= 1 precision digit.211 assertEquals(util.bytesToString(2.55 * TB - 1), '2.5 TB');212 assertEquals(util.bytesToString(2.55 * TB), '2.6 TB');213 assertEquals(util.bytesToString(PB - 0.05 * TB - 1), '1,023.9 TB');214 assertEquals(util.bytesToString(PB - 0.05 * TB), '1,024 TB');215 assertEquals(util.bytesToString(PB - 1), '1,024 TB');216 assertEquals(util.bytesToString(PB), '1 PB');217 // Above 1PB is displayed as a number of PBs with <= 1 precision digit.218 assertEquals(util.bytesToString(2.55 * PB - 1), '2.5 PB');219 assertEquals(util.bytesToString(2.55 * PB), '2.6 PB');220}221/**222 * Tests the formatting of util.bytesToString with added precision digits.223 *224 * Useful information regarding the below assertions:225 * 647 bytes = 0.6318359375 KB.226 * bytesToString() internally uses Number.toLocaleString() which outputs at most227 * 3 precision digits in en-US.228 */229function testBytesToStringWithAddedPrecision() {230 const KB = 2 ** 10;231 const MB = 2 ** 20;232 const GB = 2 ** 30;233 const TB = 2 ** 40;234 const PB = 2 ** 50;235 // Up to 1KB formatting unchanged.236 assertEquals(util.bytesToString(0, 1), '0 bytes');237 assertEquals(util.bytesToString(10, 2), '10 bytes');238 assertEquals(util.bytesToString(KB - 1, 3), '1,023 bytes');239 // Exact values, no trailing 0s regardless of precision.240 assertEquals(util.bytesToString(2 * KB, 1), '2 KB');241 assertEquals(util.bytesToString(2 * MB, 2), '2 MB');242 assertEquals(util.bytesToString(2 * GB, 3), '2 GB');243 assertEquals(util.bytesToString(2 * TB, 4), '2 TB');244 assertEquals(util.bytesToString(2 * PB, 5), '2 PB');245 // up to MB, initially no precision digits.246 assertEquals(util.bytesToString(2 * KB + 647), '3 KB');247 assertEquals(util.bytesToString(2 * KB + 647, 0), '3 KB');248 assertEquals(util.bytesToString(2 * KB + 647, 1), '2.6 KB');249 assertEquals(util.bytesToString(2 * KB + 647, 2), '2.63 KB');250 assertEquals(util.bytesToString(2 * KB + 647, 3), '2.632 KB');251 assertEquals(util.bytesToString(2 * KB + 647, 4), '2.632 KB');252 assertEquals(util.bytesToString(200 * KB + 647, 1), '200.6 KB');253 // From 1MB, up to 1 precision digit + added precision.254 assertEquals(util.bytesToString(2 * MB + 647 * KB), '2.6 MB');255 assertEquals(util.bytesToString(2 * MB + 647 * KB, 0), '2.6 MB');256 assertEquals(util.bytesToString(2 * MB + 647 * KB, 1), '2.63 MB');257 assertEquals(util.bytesToString(2 * MB + 647 * KB, 2), '2.632 MB');258 assertEquals(util.bytesToString(2 * MB + 647 * KB, 3), '2.632 MB');259 assertEquals(util.bytesToString(200 * MB + 647 * KB, 1), '200.63 MB');260 // Up to 1TB.261 assertEquals(util.bytesToString(2 * GB + 647 * MB), '2.6 GB');262 assertEquals(util.bytesToString(2 * GB + 647 * MB, 0), '2.6 GB');263 assertEquals(util.bytesToString(2 * GB + 647 * MB, 1), '2.63 GB');264 assertEquals(util.bytesToString(2 * GB + 647 * MB, 2), '2.632 GB');265 assertEquals(util.bytesToString(2 * GB + 647 * MB, 3), '2.632 GB');266 assertEquals(util.bytesToString(200 * GB + 647 * MB, 1), '200.63 GB');267 // Up to 1PB.268 assertEquals(util.bytesToString(2 * TB + 647 * GB), '2.6 TB');269 assertEquals(util.bytesToString(2 * TB + 647 * GB, 0), '2.6 TB');270 assertEquals(util.bytesToString(2 * TB + 647 * GB, 1), '2.63 TB');271 assertEquals(util.bytesToString(2 * TB + 647 * GB, 2), '2.632 TB');272 assertEquals(util.bytesToString(2 * TB + 647 * GB, 3), '2.632 TB');273 assertEquals(util.bytesToString(200 * TB + 647 * GB, 1), '200.63 TB');274 // Above 1PB.275 assertEquals(util.bytesToString(2 * PB + 647 * TB), '2.6 PB');276 assertEquals(util.bytesToString(2 * PB + 647 * TB, 0), '2.6 PB');277 assertEquals(util.bytesToString(2 * PB + 647 * TB, 1), '2.63 PB');278 assertEquals(util.bytesToString(2 * PB + 647 * TB, 2), '2.632 PB');279 assertEquals(util.bytesToString(2 * PB + 647 * TB, 3), '2.632 PB');280 assertEquals(util.bytesToString(200 * PB + 647 * TB, 1), '200.63 PB');...

Full Screen

Full Screen

TestHPKE.js

Source:TestHPKE.js Github

copy

Full Screen

1const CTX = require('../../index').CTX;2// C25519 context3function C25519() {4 var ctx = new CTX('C25519');5 6 console.log("X25519 Curve "+ "");7 var config_id=0x520;8 var pkE=[];9 var INFO=ctx.ECDH.stringtobytes("4f6465206f6e2061204772656369616e2055726e");10 var psk=ctx.ECDH.stringtobytes("0247fd33b913760fa1fa51e1892d9f307fbe65eb171e8132c2af18555a738b82");11 var pskID=ctx.ECDH.stringtobytes("456e6e796e20447572696e206172616e204d6f726961");12 var plain=ctx.ECDH.stringtobytes("4265617574792069732074727574682c20747275746820626561757479");13 var aad=ctx.ECDH.stringtobytes("436f756e742d30");14 console.log("Testing HPKE code ");15 var key=[];16 var nonce=[];17 var exp_secret=[];18 var cipher=[];19 var tag=[];20 var seedE,seedR,seedS;21 var skR=[];22 var skE=[];23 var skS=[];24 var pkR=[];25 var pkS=[];26 var pkE=[];27 var mode,Z;28// Mode 029 mode=0;30 console.log("Mode 0 ");31 seedE=ctx.ECDH.stringtobytes("591c66abd531b9c8287cf76ac053efba38d61e994e7f656c30dab6723a8af9ce");32 seedR=ctx.ECDH.stringtobytes("8a219e9a42233826f165d2c1036399fa84cfb3bcb93872bc49287dfbe6f1fec9");33 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);34 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);35 Z=ctx.HPKE.encap(config_id,skE,pkE,pkR);36 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );37 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );38 Z=ctx.HPKE.decap(config_id,skR,pkE,pkR);39 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );40 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,null,null);41 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );42 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );43 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );44 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);45 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );46 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );47// Mode 148 mode=1;49 console.log(" Mode 1 ");50 seedE=ctx.ECDH.stringtobytes("f39542a6e45dc0e6225de671455fea9d918d4fa241c7fb301895a138ce7c2f52");51 seedR=ctx.ECDH.stringtobytes("5aa0335739cb3dbafce48d5d9cccd7d499b0727b445522e1408aba8171aabfae");52 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);53 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);54 Z=ctx.HPKE.encap(config_id,skE,pkE,pkR);55 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );56 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );57 Z=ctx.HPKE.decap(config_id,skR,pkE,pkR);58 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );59 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,psk,pskID);60 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );61 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );62 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );63 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);64 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );65 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );66// Mode 267 mode=2;68 console.log(" Mode 2 ");69 seedE=ctx.ECDH.stringtobytes("0b119a7a132355f3c2a0ad03e10e252d7292fcde480e726d03a81f127d02c050");70 seedR=ctx.ECDH.stringtobytes("874ba77ded181cd1cb4f2b4f37386a5b2b86c84c57d2a6d1b93a05fb5edd69f0");71 seedS=ctx.ECDH.stringtobytes("2e369ba803dcee17dba926e4252b8dd9a47417a35bcf90f0e55e4af85c83153b");72 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);73 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);74 ctx.HPKE.DeriveKeyPair(config_id,skS,pkS,seedS);75 Z=ctx.HPKE.authEncap(config_id,skE,skS,pkE,pkR,pkS);76 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );77 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );78 Z=ctx.HPKE.authDecap(config_id,skR,pkE,pkR,pkS);79 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );80 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,null,null);81 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );82 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );83 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );84 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);85 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );86 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );87// Mode 388 mode=3;89 console.log(" Mode 3 ");90 seedE=ctx.ECDH.stringtobytes("96360b18f7822f85f4a0a1dd200d00ab82ad0032b05a1f34cb120a0cbda4865a");91 seedR=ctx.ECDH.stringtobytes("48710faa5c8b8b2a4447c9ccf1cc232fb49f6c0fd04b151949757e15b414eea8");92 seedS=ctx.ECDH.stringtobytes("dd413f8d2d4b195a7cd0793453d04660203a51db65a57d16c2a720e6d44e526c");93 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);94 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);95 ctx.HPKE.DeriveKeyPair(config_id,skS,pkS,seedS);96 Z=ctx.HPKE.authEncap(config_id,skE,skS,pkE,pkR,pkS);97 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );98 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );99 Z=ctx.HPKE.authDecap(config_id,skR,pkE,pkR,pkS);100 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );101 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,psk,pskID);102 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );103 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );104 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );105 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);106 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );107 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );108}109// NIST521 context110function NIST521() {111 var ctx = new CTX('NIST521');112 113 console.log("NIST521 Curve "+ "");114 var config_id=0xB12;115 var pkE=[];116 var INFO=ctx.ECDH.stringtobytes("4f6465206f6e2061204772656369616e2055726e");117 var psk=ctx.ECDH.stringtobytes("0247fd33b913760fa1fa51e1892d9f307fbe65eb171e8132c2af18555a738b82");118 var pskID=ctx.ECDH.stringtobytes("456e6e796e20447572696e206172616e204d6f726961");119 var plain=ctx.ECDH.stringtobytes("4265617574792069732074727574682c20747275746820626561757479");120 var aad=ctx.ECDH.stringtobytes("436f756e742d30");121 console.log("Testing HPKE code ");122 var key=[];123 var nonce=[];124 var exp_secret=[];125 var cipher=[];126 var tag=[];127 var seedE,seedR,seedS;128 var skR=[];129 var skE=[];130 var skS=[];131 var pkR=[];132 var pkS=[];133 var pkE=[];134 var mode,Z;135// Mode 0136 mode=0;137 console.log("Mode 0 ");138 seedE=ctx.ECDH.stringtobytes("3fdb7eab3a6a99de8abbcb507be5704ae6a8994008b8a8e6b63fbd97fa8619c66bd8665c22079939f3f63f978c5806802b22ba5bb396da9cf252ee67068bf57461bf");139 seedR=ctx.ECDH.stringtobytes("2e99ac709379c7eb15ca068253bbae4dd6297c2397f47a89b8cb3ef4e83f235f83cb1ce3d2f754c47431ff0d0d8d2c429a7b6768d9524c3be60b9fb7749c49cb816b");140 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);141 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);142 Z=ctx.HPKE.encap(config_id,skE,pkE,pkR);143 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );144 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );145 Z=ctx.HPKE.decap(config_id,skR,pkE,pkR);146 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );147 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,null,null);148 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );149 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );150 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );151 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);152 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );153 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );154// Mode 1155 mode=1;156 console.log(" Mode 1 ");157 seedE=ctx.ECDH.stringtobytes("ae300665d34d5ab7c0508a94a741ba2cb285966106ba9cefbe1f9c24c3eb626108d0c9ccc8291d90c50c6d04ac181ccd8efc2cc52383eb205637a84d2be5362bf247");158 seedR=ctx.ECDH.stringtobytes("dbbda5e5a54ee85cfe076e4746ceb971bed338a7fe0b625d6c7c28b3c82c8128258906a52543655ecb62889e9dbe8feec747d06e4216f88ca4adba200179e0e75276");159 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);160 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);161 Z=ctx.HPKE.encap(config_id,skE,pkE,pkR);162 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );163 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );164 Z=ctx.HPKE.decap(config_id,skR,pkE,pkR);165 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );166 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,psk,pskID);167 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );168 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );169 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );170 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);171 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );172 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );173// Mode 2174 mode=2;175 console.log(" Mode 2 ");176 seedE=ctx.ECDH.stringtobytes("11c0c7337b294452826e14a7f6c9e7981a03c467a08f47a8b478b37f3e9c90266898e3c3f8e84235a6a2837269c84b355d7f5ca133085172a08f00c3857da8a1410b");177 seedR=ctx.ECDH.stringtobytes("bb56b3452a80ad82b2d48c19ce76194a198eefdb67040959bc9e479db0682a4b5b46d7d020df66864d374b25deb5927144e3f08f2f9eacdd5f54b8b5c65d91ee211f");178 seedS=ctx.ECDH.stringtobytes("bab663b9c05f680f401a494ae8c8714fd95cbcd56a01e9e8194b4b3da863a5e8313d4916dc58f6d3aaa2dafe420ae81b2a6c0075223afc6b13f3734a26ca30da5e38");179 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);180 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);181 ctx.HPKE.DeriveKeyPair(config_id,skS,pkS,seedS);182 Z=ctx.HPKE.authEncap(config_id,skE,skS,pkE,pkR,pkS);183 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );184 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );185 Z=ctx.HPKE.authDecap(config_id,skR,pkE,pkR,pkS);186 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );187 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,null,null);188 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );189 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );190 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );191 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);192 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );193 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );194// Mode 3195 mode=3;196 console.log(" Mode 3 ");197 seedE=ctx.ECDH.stringtobytes("4ebb461a5c46330d6de3a40d19ac499cc206733cf1a4fb3ba922d976aa1c45848668f04a3b5a4845a0d1c83755967d8914a9824fbb8823d161c16c93c51636e1ad89");198 seedR=ctx.ECDH.stringtobytes("1ae2f1008c46c7a6e9275b1e29c906475c6bc019b1dfc38cbce68c5233de9d33ba93fe9d7b9ea5beb04f4adc5a3b72238f6e3d904d29eb0680ea240103d3335a3c47");199 seedS=ctx.ECDH.stringtobytes("e0f2ada4f2a900fded767dc9868119ee3e4767afac667a780b68e5e2b4d7d363dbf02717ab314369c45f34dcec3de384a65e8453a971ad0353a507f34dc1d5d9b8f5");200 ctx.HPKE.DeriveKeyPair(config_id,skE,pkE,seedE);201 ctx.HPKE.DeriveKeyPair(config_id,skR,pkR,seedR);202 ctx.HPKE.DeriveKeyPair(config_id,skS,pkS,seedS);203 Z=ctx.HPKE.authEncap(config_id,skE,skS,pkE,pkR,pkS);204 console.log("pKE : 0x"+ctx.ECDH.bytestostring(pkE) );205 console.log("Encapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );206 Z=ctx.HPKE.authDecap(config_id,skR,pkE,pkR,pkS);207 console.log("Decapsulated Z : 0x"+ctx.ECDH.bytestostring(Z) );208 ctx.HPKE.keySchedule(config_id,key,nonce,exp_secret,mode,Z,INFO,psk,pskID);209 console.log("Key : 0x"+ctx.ECDH.bytestostring(key) );210 console.log("Nonce : 0x"+ctx.ECDH.bytestostring(nonce) );211 console.log("Exporter secret : 0x"+ctx.ECDH.bytestostring(exp_secret) );212 ctx.GCM.encrypt(cipher,tag,key,nonce,aad,plain);213 console.log("Cipher : 0x"+ctx.ECDH.bytestostring(cipher) );214 console.log("Tag : 0x"+ctx.ECDH.bytestostring(tag) );215}216C25519();217console.log("\n");218NIST521();...

Full Screen

Full Screen

bytes-to-string-test.js

Source:bytes-to-string-test.js Github

copy

Full Screen

2import { describe, it } from 'mocha';3import bytesToString from 'ember-cli-onedata-common/utils/bytes-to-string';4describe('Unit | Utility | bytes to string', function () {5 it('can convert byte size to YiB string', function () {6 let result = bytesToString(Math.pow(1024, 8), { iecFormat: true });7 expect(result).to.be.equal('1 YiB');8 });9 it('can convert byte size to ZiB string', function () {10 let result = bytesToString(Math.pow(1024, 7), { iecFormat: true });11 expect(result).to.be.equal('1 ZiB');12 });13 it('can convert byte size to EiB string', function () {14 let result = bytesToString(Math.pow(1024, 6), { iecFormat: true });15 expect(result).to.be.equal('1 EiB');16 });17 it('can convert byte size to PiB string', function () {18 let result = bytesToString(Math.pow(1024, 5), { iecFormat: true });19 expect(result).to.be.equal('1 PiB');20 });21 it('can convert byte size to TiB string', function () {22 let result = bytesToString(Math.pow(1024, 4), { iecFormat: true });23 expect(result).to.be.equal('1 TiB');24 });25 it('can convert byte size to GiB string', function () {26 let result = bytesToString(Math.pow(1024, 3), { iecFormat: true });27 expect(result).to.be.equal('1 GiB');28 });29 it('can convert byte size to MiB string', function () {30 let result = bytesToString(Math.pow(1024, 2), { iecFormat: true });31 expect(result).to.be.equal('1 MiB');32 });33 it('can convert byte size to KiB string', function () {34 let result = bytesToString(1024, { iecFormat: true });35 expect(result).to.be.equal('1 KiB');36 });37 it('can convert byte size to YB string', function () {38 let result = bytesToString(Math.pow(1000, 8), { iecFormat: false });39 expect(result).to.be.equal('1 YB');40 });41 it('can convert byte size to ZB string', function () {42 let result = bytesToString(Math.pow(1000, 7), { iecFormat: false });43 expect(result).to.be.equal('1 ZB');44 });45 it('can convert byte size to EB string', function () {46 let result = bytesToString(Math.pow(1000, 6), { iecFormat: false });47 expect(result).to.be.equal('1 EB');48 });49 it('can convert byte size to PB string', function () {50 let result = bytesToString(Math.pow(1000, 5), { iecFormat: false });51 expect(result).to.be.equal('1 PB');52 });53 it('can convert byte size to TB string', function () {54 let result = bytesToString(Math.pow(1000, 4), { iecFormat: false });55 expect(result).to.be.equal('1 TB');56 });57 it('can convert byte size to GB string', function () {58 let result = bytesToString(Math.pow(1000, 3), { iecFormat: false });59 expect(result).to.be.equal('1 GB');60 });61 it('can convert byte size to MB string', function () {62 let result = bytesToString(Math.pow(1000, 2), { iecFormat: false });63 expect(result).to.be.equal('1 MB');64 });65 it('can convert byte size to KB string', function () {66 let result = bytesToString(1000, { iecFormat: false });67 expect(result).to.be.equal('1 KB');68 });69 it('rounds size in string to 1 digit after comma by default (w/o IEC)', function () {70 let result = bytesToString(1251111, { iecFormat: false });71 expect(result).to.be.equal('1.3 MB');72 });73 it('supports format option with iec', function () {74 let result = bytesToString(1073741824, { format: 'iec' });75 expect(result).to.be.equal('1 GiB');76 });77 it('can convert to bit', function () {78 let result = bytesToString(1, { format: 'bit' });79 expect(result).to.be.equal('8 b');80 });81 82 it('can convert to kbit', function () {83 let result = bytesToString(8000, { format: 'bit' });84 expect(result).to.be.equal('64 kb');85 });86 it('can convert to Mbit', function () {87 let result = bytesToString(625000, { format: 'bit' });88 expect(result).to.be.equal('5 Mb');89 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 if (err) {4 return console.error(err);5 }6 client.getTestResults(data.data.testId, function(err, data) {7 if (err) {8 return console.error(err);9 }10 console.log(data.data.median.firstView.bytesIn);11 console.log(wpt.bytesToString(data.data.median.firstView.bytesIn));12 });13});14var wpt = require('webpagetest');15var client = wpt('www.webpagetest.org');16 if (err) {17 return console.error(err);18 }19 client.getTestResults(data.data.testId, function(err, data) {20 if (err) {21 return console.error(err);22 }23 console.log(data);24 });25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3e6t.getTestStatus('150611_4H_1R', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 console.log(wpt.bytesToString(data.data.average.firstView.bytesIn));7 console.log(wpt.bytesToString(data.data.average.firstView.bytesOut));8 console.log(wpt.bytesToString(data.data.average.firstView.bytesInDoc));9 console.log(wpt.bytesToString(data.data.average.firstView.bytesOutDoc));10 console.log(wpt.bytesToString(data.data.average.firstView.bytesInDoc));11 console.log(wpt.bytesToString(da4a.data.average.firstView.bytesOutDoc));12});13### getTestStatus(testId, callback)14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getTestStatus('150611_4H_1R', function(err, data) {17 if (err) return console.error(err);18 console.log(data);19});20### getTestResults(testId, callback)21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTestResults('150611_4H_1R', function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});27### getLocations(callback)28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getLocations(function(err, data) {31 if (err) return console.error(err);32 console.log(data);33});34```agetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wp = requir('wpt.j');2var util = require('uil3 new WebPageTest('www.webpagetest.org','A.3c8f2d2c0d4f7e6c1e8e9d9c4b4e4f4b');4 if (err) {5 console.log(err);6 } else {7 console.log(util.inspect(data));8 }9});10### getBrowsers(callback)11var wpt = require('webpagetest');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var util = require('util');3var wpt = new WebPageTest('www.webpagetest.org', 'A.3c8f2d2c0d4f7e6c1e8e9d9c4b4e4f4b');4 if (err) {5 console.log(err);6 } else {7 console.log(util.inspect(data));8 }9});Url method of wptb.js

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('150611_4H_1R', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 console.log(wpt.bytesToString(data.data.average.firstView.bytesIn));7 console.log(wpt.bytesToString(data.data.average.firstView.bytesOut));8 console.log(wpt.bytesToString(data.data.average.firstView.bytesInDoc));9 console.log(wpt.bytesToString(data.data.average.firstView.bytesOutDoc));10 console.log(wpt.bytesToString(data.data.average.firstView.bytesInDoc));11 console.log(wpt.bytesToString(data.data.average.firstView.bytesOutDoc));12});13### getTestStatus(testId, callback)14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getTestStatus('150611_4H_1R', function(err, data) {17 if (err) return console.error(err);18 console.log(data);19});20### getTestResults(testId, callback)21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTestResults('150611_4H_1R', function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});27### getLocations(callback)28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getLocations(function(err, data) {31 if (err) return console.error(err);32 console.log(data);33});34### getBrowsers(callback)35var wpt = require('webpagetest');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful