Skip to content

Commit 77a8314

Browse files
Fix the crypto tests.
1 parent f1d0b05 commit 77a8314

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/test/common/crypto.unit.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
'use strict';
55

66
import { assert, expect } from 'chai';
7+
import * as fsextra from 'fs-extra';
78
import * as path from 'path';
89
import { CryptoUtils } from '../../client/common/crypto';
9-
import { FileSystem } from '../../client/common/platform/fileSystem';
1010
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../constants';
1111

1212
// tslint:disable-next-line: max-func-body-length
1313
suite('Crypto Utils', async () => {
1414
let crypto: CryptoUtils;
15-
const fs = new FileSystem();
16-
const file = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'common', 'randomWords.txt');
1715
setup(() => {
1816
crypto = new CryptoUtils();
1917
});
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+
2024
test('If hashFormat equals `number`, method createHash() returns a number', async () => {
2125
const hash = crypto.createHash('blabla', 'number');
2226
assert.typeOf(hash, 'number', 'Type should be a number');
@@ -52,8 +56,7 @@ suite('Crypto Utils', async () => {
5256
assert.notEqual(hash1, hash2, 'Hashes should be different strings');
5357
});
5458
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();
5760
const buckets: number[] = Array(100).fill(0);
5861
const hashes = Array(10).fill(0);
5962
for (const w of wordList) {
@@ -72,8 +75,7 @@ suite('Crypto Utils', async () => {
7275
}
7376
});
7477
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();
7779
const buckets: number[] = Array(100).fill(0);
7880
let hashes: number[] = [];
7981
let totalDifference = 0;

0 commit comments

Comments
 (0)