From e40c62ddd8737b5352f730ea7ed6979de46d6da8 Mon Sep 17 00:00:00 2001 From: Charlie Moore <58339043+charliejmoore@users.noreply.github.com> Date: Sun, 19 Sep 2021 02:45:47 -0400 Subject: [PATCH] chore: merge Tests for check flat case (#689) * update function documentation and name to match js convention * add additional documentation explaining what the function does * add tests for checkFlatCase function * fix standard.js errors --- String/CheckFlatCase.js | 14 ++++++++------ String/test/CheckFlatCase.test.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 String/test/CheckFlatCase.test.js diff --git a/String/CheckFlatCase.js b/String/CheckFlatCase.js index 7e842211b..709825edd 100644 --- a/String/CheckFlatCase.js +++ b/String/CheckFlatCase.js @@ -1,13 +1,15 @@ -// CheckFlatCase method checks the given string is in flatcase or not. +// checkFlatCase method checks if the given string is in flatcase or not. Flatcase is a convention +// where all letters are in lowercase, and there are no spaces between words. +// thisvariable is an example of flatcase. In camelCase it would be thisVariable, snake_case this_variable and so on. // Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming) /** - * CheckFlatCase method returns true if the string in flatcase, else return the false. - * @param {String} varname the name of the variable to check. - * @returns `Boolean` return true if the string is in flatcase, else return false. + * checkFlatCase method returns true if the string in flatcase, else return the false. + * @param {string} varname the name of the variable to check. + * @returns {boolean} return true if the string is in flatcase, else return false. */ -const CheckFlatCase = (varname) => { +const checkFlatCase = (varname) => { // firstly, check that input is a string or not. if (typeof varname !== 'string') { return new TypeError('Argument is not a string.') @@ -17,4 +19,4 @@ const CheckFlatCase = (varname) => { return pat.test(varname) } -module.exports = CheckFlatCase +export { checkFlatCase } diff --git a/String/test/CheckFlatCase.test.js b/String/test/CheckFlatCase.test.js new file mode 100644 index 000000000..0277f7c0e --- /dev/null +++ b/String/test/CheckFlatCase.test.js @@ -0,0 +1,18 @@ +import { checkFlatCase } from '../CheckFlatCase' + +describe('checkFlatCase function', () => { + it('should return false when the input string is not in flatcase', () => { + const actual = checkFlatCase('this is not in flatcase') + expect(actual).toBe(false) + }) + + it('should return true when the input string is a single letter character', () => { + const actual = checkFlatCase('a') + expect(actual).toBe(true) + }) + + it('should return true when the input string is a string of lowercase letter characters with no spaces', () => { + const actual = checkFlatCase('abcdefghijklmnopqrstuvwxyz') + expect(actual).toBe(true) + }) +})