Skip to content

Commit

Permalink
Adds missing return types
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrypula committed Nov 2, 2019
1 parent 3025b4d commit 4d6fc1b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/lib/1-data-link-layer/data-link-layer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Data link layer', (): void => {
const rxBytesCollector: RxBytesCollector[] = [];
let rxTimeTickState: RxTimeTickState;

spyRx = spyOn(dataLinkLayer.physicalLayer, 'rx').and.callFake(() => rx.shift());
spyRx = spyOn(dataLinkLayer.physicalLayer, 'rx').and.callFake((): number => rx.shift());
spyRxTimeTick = spyOn(dataLinkLayer, 'rxTimeTick').and.callThrough();

do {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/1-data-link-layer/frame/frame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('Frame', (): void => {
describe('getRawBytes', (): void => {
it('should properly generate raw bytes (header + payload) for given payload', (): void => {
// TODO implement
// const fakeCheckSequence = getBytesFromHex('ab bc de');
// const fakeCheckSequence: number[] = getBytesFromHex('ab bc de');
// const frame: FrameInterface = createFrame(frameConfig);
// const payload = getBytesFromHex('06 07 08 09 0a 43 64 34');
// const payload: number[] = getBytesFromHex('06 07 08 09 0a 43 64 34');
//
// spyOn(fromCheckAlgorithms, 'getCheckAlgorithmImplementation').and.callFake(() => fakeCheckSequence);
// spyOn(fromCheckAlgorithms, 'getCheckAlgorithmImplementation').and.callFake((): number[] => fakeCheckSequence);
// expect(frame.setPayload(payload).getRawBytes()).toEqual([...fakeCheckSequence, ...payload]);
});
});
Expand All @@ -73,8 +73,8 @@ describe('Frame', (): void => {
it('should detect errors', (): void => {
// TODO implement
// const frame: FrameInterface = createFrame(frameConfig);
// const payload = getBytesFromHex('f6 f7 f8 f9 fa fb fc fd');
// let checksum = getBytesFromHex('ab cd ef');
// const payload: number[] = getBytesFromHex('f6 f7 f8 f9 fa fb fc fd');
// let checksum: number[] = getBytesFromHex('ab cd ef');
//
// spyOn(fromCheckAlgorithms, 'getCheckAlgorithmImplementation').and.returnValue(() => () => [...checksum]);
// frame.setPayload(payload);
Expand Down
32 changes: 22 additions & 10 deletions src/lib/1-data-link-layer/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ describe('Utils', (): void => {
const result: number[][] = [];
const lengthMin = 3;

fromUtils.allPossibleRightAlignedArrays([100, 200, 300, 400, 500, 600], lengthMin, (output: number[]) =>
result.push(output)
);
fromUtils.allPossibleRightAlignedArrays([100, 200, 300, 400, 500, 600], lengthMin, (output: number[]): void => {
result.push(output);
});
expect(result).toEqual([
[100, 200, 300, 400, 500, 600],
/**/ [200, 300, 400, 500, 600],
Expand All @@ -34,7 +34,9 @@ describe('Utils', (): void => {
const result: number[][] = [];
const lengthMin = 3;

fromUtils.allPossibleRightAlignedArrays([100], lengthMin, (output: number[]) => result.push(output));
fromUtils.allPossibleRightAlignedArrays([100], lengthMin, (output: number[]): void => {
result.push(output);
});
expect(result).toEqual([]);
});
});
Expand All @@ -46,7 +48,13 @@ describe('Utils', (): void => {
const result: number[][] = [];
const range = 3;

fromUtils.allPossibleSinglePositionErrors(data, () => result.push(data.slice(0)), range);
fromUtils.allPossibleSinglePositionErrors(
data,
(): void => {
result.push(data.slice(0));
},
range
);
expect(result).toEqual([[0, 2, 0], [2, 2, 0], [1, 0, 0], [1, 1, 0], [1, 2, 1], [1, 2, 2]]);
expect(data).toEqual(dataOriginal);
});
Expand All @@ -56,7 +64,9 @@ describe('Utils', (): void => {
const data: number[] = dataOriginal.slice(0);
let counter = 0;

fromUtils.allPossibleSinglePositionErrors(data, () => counter++);
fromUtils.allPossibleSinglePositionErrors(data, (): void => {
counter++;
});
expect(data).toEqual(dataOriginal);
expect(counter).toEqual(dataOriginal.length * 255);
});
Expand All @@ -67,9 +77,9 @@ describe('Utils', (): void => {
const result: number[][] = [];
const scrambleSequence = [10, 20, 30, 12];

fromUtils.allPossibleUnScrambledArrays([0, 100, 200], scrambleSequence, (scrambledArray: number[]) =>
result.push(scrambledArray)
);
fromUtils.allPossibleUnScrambledArrays([0, 100, 200], scrambleSequence, (scrambledArray: number[]): void => {
result.push(scrambledArray);
});
expect(result).toEqual([[256 - 10, 80, 170], [256 - 20, 70, 188], [256 - 30, 88, 190], [256 - 12, 90, 180]]);
});

Expand All @@ -81,7 +91,9 @@ describe('Utils', (): void => {
fromUtils.allPossibleUnScrambledArrays(
[16, 2],
scrambleSequence,
(output: number[]) => result.push(output),
(output: number[]): void => {
result.push(output);
},
range
);
expect(result).toEqual([[11, 16], [10, 17]]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ TODO #1:
+ we don't need separate history for odd & even rxRawBytes,
+ we can return frames at getRxBytesCollection/getRxBytesErrorCorrectedCollection directly from history
+ add createFrame and FrameInterface, as currently it's not possible to mock isValid function
- add unit test for multiple valid frames detection (scramble sequence equal [0] for test simplification purposes)
+ add unit test for multiple valid frames detection (scramble sequence equal [0] for test simplification purposes)
- find better solution for TRUE/FALSE constants in 1-data-link-layer/constant.ts file
- add wrappers for setTimeout, setInterval and 'new Date().getTime()' at shared directory
- finalize advanced chat example
Expand Down
6 changes: 3 additions & 3 deletions src/lib/shared/check-algorithms/check-algorithms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('Check algorithms', (): void => {
checkAlgorithmImplementation: CheckAlgorithmImplementation,
testCases: TestCaseInOut[]
): void => {
testCases.forEach((testCase: TestCaseInOut) =>
expect(getHexFromBytes(checkAlgorithmImplementation(getBytesFromText(testCase.in)))).toEqual(testCase.out)
);
testCases.forEach((testCase: TestCaseInOut): void => {
expect(getHexFromBytes(checkAlgorithmImplementation(getBytesFromText(testCase.in)))).toEqual(testCase.out);
});
};

describe('getCrc08', (): void => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/shared/utf8/decode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getBytesFromHex } from '@shared/utils';
describe('Utf8 decode', (): void => {
describe('getTextFromUtf8Bytes', (): void => {
const runTestCases = (testCases: TestCaseInOut[]): void => {
testCases.forEach((testCase: TestCaseInOut) =>
expect(getTextFromUtf8Bytes(getBytesFromHex(testCase.in))).toEqual(testCase.out)
);
testCases.forEach((testCase: TestCaseInOut): void => {
expect(getTextFromUtf8Bytes(getBytesFromHex(testCase.in))).toEqual(testCase.out);
});
};

it('should work', (): void => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/shared/utf8/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getHexFromBytes } from '@shared/utils';
describe('Utf8 encode', (): void => {
describe('getUtf8BytesFromText', (): void => {
const runTestCases = (testCases: TestCaseInOut[]): void => {
testCases.forEach((testCase: TestCaseInOut) =>
expect(getHexFromBytes(getUtf8BytesFromText(testCase.in))).toEqual(testCase.out)
);
testCases.forEach((testCase: TestCaseInOut): void => {
expect(getHexFromBytes(getUtf8BytesFromText(testCase.in))).toEqual(testCase.out);
});
};

it('should work', (): void => {
Expand Down

0 comments on commit 4d6fc1b

Please sign in to comment.