- Unify test data for nonexistence of an object/string and collection. - Introduce more test through adding missing test data to existing tests. - Improve logic for checking absence of values to match tests. - Add missing tests for absent value validation. - Update documentation to include shared test functionality.
97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
import 'mocha';
|
|
import { expect } from 'chai';
|
|
import { scrambledEqual, sequenceEqual } from '@/application/Common/Array';
|
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
|
import { ComparerTestScenario } from './Array.ComparerTestScenario';
|
|
|
|
describe('Array', () => {
|
|
describe('scrambledEqual', () => {
|
|
describe('throws if arguments are absent', () => {
|
|
describe('first argument is absent', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing first array';
|
|
const firstArray = absentValue;
|
|
const secondArray = [];
|
|
// act
|
|
const act = () => scrambledEqual(firstArray, secondArray);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('second argument is absent', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing second array';
|
|
const firstArray = [];
|
|
const secondArray = absentValue;
|
|
// act
|
|
const act = () => scrambledEqual(firstArray, secondArray);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
describe('returns as expected', () => {
|
|
// arrange
|
|
const scenario = new ComparerTestScenario()
|
|
.addSameItemsWithSameOrder(true)
|
|
.addSameItemsWithDifferentOrder(true)
|
|
.addDifferentItemsWithSameLength(false)
|
|
.addDifferentItemsWithDifferentLength(false);
|
|
// act
|
|
scenario.forEachCase((testCase) => {
|
|
it(testCase.name, () => {
|
|
const actual = scrambledEqual(testCase.first, testCase.second);
|
|
// assert
|
|
expect(actual).to.equal(testCase.expected);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('sequenceEqual', () => {
|
|
describe('throws if arguments are absent', () => {
|
|
describe('first argument is absent', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing first array';
|
|
const firstArray = absentValue;
|
|
const secondArray = [];
|
|
// act
|
|
const act = () => sequenceEqual(firstArray, secondArray);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('second argument is absent', () => {
|
|
itEachAbsentObjectValue((absentValue) => {
|
|
// arrange
|
|
const expectedError = 'missing second array';
|
|
const firstArray = [];
|
|
const secondArray = absentValue;
|
|
// act
|
|
const act = () => sequenceEqual(firstArray, secondArray);
|
|
// assert
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
});
|
|
describe('returns as expected', () => {
|
|
// arrange
|
|
const scenario = new ComparerTestScenario()
|
|
.addSameItemsWithSameOrder(true)
|
|
.addSameItemsWithDifferentOrder(true)
|
|
.addDifferentItemsWithSameLength(false)
|
|
.addDifferentItemsWithDifferentLength(false);
|
|
// act
|
|
scenario.forEachCase((testCase) => {
|
|
it(testCase.name, () => {
|
|
const actual = scrambledEqual(testCase.first, testCase.second);
|
|
// assert
|
|
expect(actual).to.equal(testCase.expected);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|