4
4
'use strict' ;
5
5
6
6
import { assert , expect } from 'chai' ;
7
+ import * as fsextra from 'fs-extra' ;
7
8
import * as path from 'path' ;
8
9
import { CryptoUtils } from '../../client/common/crypto' ;
9
- import { FileSystem } from '../../client/common/platform/fileSystem' ;
10
10
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../constants' ;
11
11
12
12
// tslint:disable-next-line: max-func-body-length
13
13
suite ( 'Crypto Utils' , async ( ) => {
14
14
let crypto : CryptoUtils ;
15
- const fs = new FileSystem ( ) ;
16
- const file = path . join ( EXTENSION_ROOT_DIR_FOR_TESTS , 'src' , 'test' , 'common' , 'randomWords.txt' ) ;
17
15
setup ( ( ) => {
18
16
crypto = new CryptoUtils ( ) ;
19
17
} ) ;
18
+ async function getWordList ( ) : Promise < string [ ] > {
19
+ const file = path . join ( EXTENSION_ROOT_DIR_FOR_TESTS , 'src' , 'test' , 'common' , 'randomWords.txt' ) ;
20
+ const words = await fsextra . readFile ( file , 'utf8' ) ;
21
+ return words . split ( '\n' ) ;
22
+ }
23
+
20
24
test ( 'If hashFormat equals `number`, method createHash() returns a number' , async ( ) => {
21
25
const hash = crypto . createHash ( 'blabla' , 'number' ) ;
22
26
assert . typeOf ( hash , 'number' , 'Type should be a number' ) ;
@@ -52,8 +56,7 @@ suite('Crypto Utils', async () => {
52
56
assert . notEqual ( hash1 , hash2 , 'Hashes should be different strings' ) ;
53
57
} ) ;
54
58
test ( 'If hashFormat equals `number`, ensure numbers are uniformly distributed on scale from 0 to 100' , async ( ) => {
55
- const words = await fs . readFile ( file ) ;
56
- const wordList = words . split ( '\n' ) ;
59
+ const wordList = await getWordList ( ) ;
57
60
const buckets : number [ ] = Array ( 100 ) . fill ( 0 ) ;
58
61
const hashes = Array ( 10 ) . fill ( 0 ) ;
59
62
for ( const w of wordList ) {
@@ -72,8 +75,7 @@ suite('Crypto Utils', async () => {
72
75
}
73
76
} ) ;
74
77
test ( 'If hashFormat equals `number`, on a scale of 0 to 100, small difference in the input on average produce large differences (about 33) in the output ' , async ( ) => {
75
- const words = await fs . readFile ( file ) ;
76
- const wordList = words . split ( '\n' ) ;
78
+ const wordList = await getWordList ( ) ;
77
79
const buckets : number [ ] = Array ( 100 ) . fill ( 0 ) ;
78
80
let hashes : number [ ] = [ ] ;
79
81
let totalDifference = 0 ;
0 commit comments