MCPcopy Create free account
hub / github.com/cryptii/cryptii / test

Method test

test/Helper/EncoderTester.js:16–88  ·  view source on GitHub ↗

* Runs tests on encoder invokable. * @param {class} EncoderInvokable * @param {Object|Object[]}

(EncoderInvokable, test)

Source from the content-addressed store, hash-verified

14 * @param {Object|Object[]}
15 */
16 static test (EncoderInvokable, test) {
17 if (Array.isArray(test)) {
18 // handle multiple tests
19 return test.forEach(test => EncoderTester.test(EncoderInvokable, test))
20 }
21
22 if (!test.direction || test.direction === 'both') {
23 // handle test in both directions
24 EncoderTester.test(EncoderInvokable, {
25 settings: test.settings,
26 direction: 'encode',
27 content: test.content,
28 expectedResult: test.expectedResult
29 })
30 EncoderTester.test(EncoderInvokable, {
31 settings: test.settings,
32 direction: 'decode',
33 content: test.expectedResult,
34 expectedResult: test.content
35 })
36 return
37 }
38
39 // read direction from test entry
40 const isEncoding = test.direction.toLowerCase() === 'encode'
41
42 // wrap content in Chain
43 const content =
44 test.content instanceof Chain
45 ? test.content
46 : Chain.wrap(test.content)
47
48 // wrap expected result in Chain
49 const expectedResult =
50 test.expectedResult instanceof Chain
51 ? test.expectedResult
52 : Chain.wrap(test.expectedResult)
53
54 // create content and result preview that will be logged
55 const contentPreview = ChainUtil.preview(content)
56 const expectedResultPreview = ChainUtil.preview(expectedResult)
57
58 it(
59 `should ${isEncoding ? 'encode' : 'decode'} ` +
60 `"${isEncoding ? contentPreview : expectedResultPreview}" ` +
61 `${isEncoding ? '=>' : '<='} ` +
62 `"${isEncoding ? expectedResultPreview : contentPreview}"`,
63 done => {
64 // create encoder brick instance
65 const encoder = new EncoderInvokable()
66
67 // apply settings, if any
68 if (test.settings) {
69 encoder.setSettingValues(test.settings)
70 }
71
72 // trigger encoder encode or decode
73 const result = isEncoding

Callers 15

RailFenceCipher.jsFile · 0.80
VigenereCipher.jsFile · 0.80
Base32.jsFile · 0.80
TrifidCipher.jsFile · 0.80
Bootstring.jsFile · 0.80
Punycode.jsFile · 0.80
ROT13.jsFile · 0.80
Ascii85.jsFile · 0.80
AffineCipher.jsFile · 0.80
Integer.jsFile · 0.80

Calls 8

toLowerCaseMethod · 0.80
wrapMethod · 0.80
previewMethod · 0.80
setSettingValuesMethod · 0.80
encodeMethod · 0.80
decodeMethod · 0.80
assertEqualMethod · 0.80
hasViewMethod · 0.80

Tested by

no test coverage detected