Skip to content

Commit

Permalink
Cleanups in unit tests names and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrypula committed Oct 25, 2019
1 parent 4839673 commit 68777a5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/lib/0-physical-layer/config-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getDspConfigsFromAllDspModes } from '@physical-layer/config-utils';
import { DspConfig, DspMode } from '@physical-layer/model';

describe('Config Utils', () => {
describe('Config utils', () => {
describe('getDspConfigsFromAllDspModes', () => {
it('should return valid list', () => {
const expectation: DspConfig[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/1-data-link-layer/config-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFrameConfigsFromAllFrameModes } from '@data-link-layer/config-utils'
import { FrameConfig, FrameMode } from '@data-link-layer/model';
import { CheckAlgorithm } from '@shared/model';

describe('Config Utils', () => {
describe('Config utils', () => {
describe('getFrameConfigsFromAllFrameModes', () => {
it('should return valid list', () => {
const expectation: FrameConfig[] = [
Expand Down
37 changes: 23 additions & 14 deletions src/lib/1-data-link-layer/data-link-layer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import CallInfo = jasmine.CallInfo;
import Spy = jasmine.Spy;
import { DataLinkLayer } from '@data-link-layer/data-link-layer';
import { ErrorCorrection, RxTimeTickState, TxTimeTickState } from '@data-link-layer/model';
import { BYTE_UNIQUE_VALUES } from '@physical-layer/constants';
import { createPhysicalLayerConfig } from '@physical-layer/physical-layer';
import { getHexFromBytes } from '@shared/utils';

describe('Data Link Layer', () => {
describe('Data link layer', () => {
let currentTime: number;
let dataLinkLayer: DataLinkLayer;
let rxIntervalMilliseconds: number;
Expand Down Expand Up @@ -69,28 +70,36 @@ describe('Data Link Layer', () => {
);
});

it('should return only one out of two identical frames that are separated by one RX step', () => {
expect(rxTest([0x00, 0x0b, 0x0b, 0x22, 0x22, 0x70, 0x70, 0x14, 0x14, 0x00, null])).toEqual([[441, [0x61]]]);
// tx intervals: .......... ========== .......... ========== ^^^ ^^^^
// \------- scrambled header -------/ scrambled data rxTime rxBytes
});
describe('Frame detection and duplicates removal', () => {
it('should return only one out of two identical frames that are separated by one RX step', () => {
expect(rxTest([0x0b, 0x0b, 0x22, 0x22, 0x70, 0x70, 0x14, 0x14, 0x00, null])).toEqual([[378, [0x61]]]);
// tx: `````````` `````````` `````````` `````````` `````````` ^^^ ^^^^
// \________________________________/ \________/ rxTime rxBytes
// scrambled 3 B of header scrambled 1B of data
});

it('should return only one out of two identical frames that are separated by one RX step (offset)', () => {
expect(rxTest([0x00, 0x00, 0x0b, 0x0b, 0x22, 0x22, 0x70, 0x70, 0x14, 0x14, 0x00, null])).toEqual([[504, [0x61]]]);
// tx intervals: .......... ========== .......... ========== ^^^ ^^^^
// \------- scrambled header -------/ scrambled data rxTime rxBytes
it('should return only one out of two identical frames that are separated by one RX step (offset)', () => {
expect(rxTest([0x00, 0x0b, 0x0b, 0x22, 0x22, 0x70, 0x70, 0x14, 0x14, 0x00, null])).toEqual([[441, [0x61]]]);
// tx: `````````` `````````` `````````` `````````` `````````` ^^^ ^^^^
// \________________________________/ \________/ rxTime rxBytes
// scrambled 3 B of header scrambled 1B of data
});
});

describe('Error Correction', () => {
describe('Error correction', () => {
it('should properly find frame even if one of the bytes is corrupted', () => {
expect(rxTest([0x0b, 0x0b, 0x22, 0x22, 0x70, 0x70, 0x14, 0x14, null])).toEqual([[378, [0x61]]]);
const byte = 0x22;

expect(rxTest([0x0b, 0x0b, byte, byte, 0x70, 0x70, 0x14, 0x14, null])).toEqual([[378, [0x61]]]);
});

it('should properly find frame even if one of the bytes is corrupted', () => {
const error = 32;
const ERROR = 32;
let byte = 0x22;

byte = (byte + ERROR) % BYTE_UNIQUE_VALUES;
dataLinkLayer.rxErrorCorrection = ErrorCorrection.On;
expect(rxTest([0x0b, 0x0b, 0x22, 0x22, 0x70 + error, 0x70 + error, 0x14, 0x14, null])).toEqual([[378, [0x61]]]);
expect(rxTest([0x0b, 0x0b, byte, byte, 0x70, 0x70, 0x14, 0x14, null])).toEqual([[378, [0x61]]]);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { findFrameCandidates, scrambler } from '@data-link-layer/utils';
import { FixedSizeBuffer } from '@shared/fixed-size-buffer';
import { getBytesFromHex, getHexFromBytes, getRandomBytes } from '@shared/utils';

describe('FrameModesBenchmark', () => {
describe('Frame modes benchmark', () => {
describe('Frame integrity', () => {
const runIntegrityTestCases = (frameMode: FrameMode, testCases: TestCaseFrameIntegrity[]) => {
const frameConfig: FrameConfig = getFrameConfig(FRAME_MODE_TO_FRAME_CONFIG_INITIALIZER_LOOK_UP[frameMode]);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/4-application-layer/transferable-file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2019 Robert Rypuła - https://github.com/robertrypula

describe('TransferableFile', () => {
describe('Transferable file', () => {
describe('...', () => {
it('should ...', () => {
// TODO implement
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { libraryInfo } from '@';

describe('Index', () => {
describe('Library Info', () => {
describe('Library info', () => {
it('should return version', () => {
expect(libraryInfo.version).toBeTruthy();
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/check-algorithms/check-algorithms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getCheckAlgorithmImplementation } from '@shared/check-algorithms/check-
import { CheckAlgorithm, CheckAlgorithmImplementation, TestCaseInOut } from '@shared/model';
import { getBytesFromText, getHexFromBytes } from '@shared/utils';

describe('CheckAlgorithms', () => {
describe('Check algorithms', () => {
const runTestCases = (checkAlgorithmImplementation: CheckAlgorithmImplementation, testCases: TestCaseInOut[]) => {
testCases.forEach((testCase: TestCaseInOut) =>
expect(getHexFromBytes(checkAlgorithmImplementation(getBytesFromText(testCase.in)))).toEqual(testCase.out)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shared/web-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2019 Robert Rypuła - https://github.com/robertrypula

describe('Web Utils', () => {
describe('Web utils', () => {
describe('fileRead', () => {
it('should ...', () => {
// TODO implement
Expand Down

0 comments on commit 68777a5

Please sign in to comment.