Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // • Take an array as argument
- // • Return false for any input that isn’t of the correct type
- // • Return true if the input array is symmetric
- // • Otherwise, return false
- const assert = require('chai').assert;
- const isSymmetric = require('../../lab/isSymmetric');
- describe('Testing if an array is symmetrical', () => {
- it('Should work with even count elements', () => {
- let inp0 = [1, 2, 3, 3, 2, 1];
- let res0 = isSymmetric(inp0);
- assert.isTrue(res0, 'result is not true');
- });
- it('Should work with odd count elements', () => {
- let inp0 = [1, 2, 3, 2, 1];
- let res0 = isSymmetric(inp0);
- assert.isTrue(res0, 'result is not true');
- });
- it('Should work with an array which contain different data types', () => {
- let inp0 = [1, '2', 3, 3, '2', 1];
- let inp1 = [1, 'string', 'center', 'string', 1];
- let arr = [];
- let obj = {};
- let inp2 = ['arr', 0, arr, obj, () => {}, obj, arr, 0, 'arr'];
- let res0 = isSymmetric(inp0);
- let res1 = isSymmetric(inp1);
- let res2 = isSymmetric(inp2);
- assert.isTrue(res0, "doesn't work with strings");
- assert.isTrue(res1, "doesn't work with strings");
- assert.isTrue(res2, "doesn't work with mixed data types");
- });
- it('Should return false if array is not symmetrical', () => {
- let inp0 = [1, 2, 3, 4, 5];
- let inp1 = [6, 5, 4, 3, 2, 1];
- let res0 = isSymmetric(inp0);
- let res1 = isSymmetric(inp1);
- assert.isFalse(res0, 'passing a normal array');
- assert.isFalse(res1, 'passing a reversed normal array');
- });
- it('Should return false if input type is not an array', () => {
- let inp0 = [1, 2, 3, 2, 1];
- let inp1 = undefined;
- let inp2 = 0;
- let inp3 = 10n;
- let inp4 = false;
- let inp5 = 'string';
- let inp6 = Symbol();
- let inp7 = { object: 'object' };
- let inp8 = function () {};
- let res0 = isSymmetric(inp0);
- let res1 = isSymmetric(inp1);
- let res2 = isSymmetric(inp2);
- let res3 = isSymmetric(inp3);
- let res4 = isSymmetric(inp4);
- let res5 = isSymmetric(inp5);
- let res6 = isSymmetric(inp6);
- let res7 = isSymmetric(inp7);
- let res8 = isSymmetric(inp8);
- assert.isNotFalse(res0);
- assert.isFalse(res1, 'passing undefined as an argument');
- assert.isFalse(res2, 'passing number as an argument');
- assert.isFalse(res3, 'passing big int as an argument');
- assert.isFalse(res4, 'passing boolean as an argument');
- assert.isFalse(res5, 'passing string as an argument');
- assert.isFalse(res6, 'passing symbol as an argument');
- assert.isFalse(res7, 'passing object as an argument');
- assert.isFalse(res8, 'passing function as an argument');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement