Skip to content

Commit 73402d5

Browse files
authored
chore: Merge pull request #733 from charliejmoore/upper-case-converstion-tests
Upper case conversion tests
2 parents d712bfd + 220e75d commit 73402d5

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

Conversions/UpperCaseConversion.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/*
2-
Explanation :- a user gives a String (it can be incomplete lower or
3-
partial lower) and then the program would convert it into a
4-
complete(all characters in upper case) upper case string. The
5-
logic we have used in the following program is: All the lower case
6-
characters (a-z) has ASCII value ranging from 97 to 122 and their
7-
corresponding upper case characters (A-Z) have ASCII values 32
2+
Explanation :- A user gives a string (it can be incomplete lowercase or
3+
partially in lowercase) and then the program converts it into a
4+
completely (all characters in uppercase) uppercase string. The
5+
logic we have used in the following program is: All the lowercase
6+
characters (a-z) has [ASCII](https://en.wikipedia.org/wiki/ASCII) value ranging from 97 to 122 and their
7+
corresponding uppercase characters (A-Z) have ASCII values 32
88
lesser than them. For example ‘a‘ has an ASCII value of 97
99
and ‘A‘ has an ASCII value of 65 (97 - 32). The same applies to other
1010
characters.
1111
*/
1212

1313
/**
14-
* UpperCaseConversion takes any case-style string and converts it to the upper case-style string.
15-
* @param {String} inputString any case style string
16-
* @returns {String} upper case string
14+
* upperCaseConversion takes any case-style string and converts it to the uppercase-style string.
15+
* @param {string} inputString Any case style string
16+
* @returns {string} Uppercase string
1717
*/
18-
const UpperCaseConversion = (inputString) => {
18+
const upperCaseConversion = (inputString) => {
1919
// Take a string and split it into characters.
2020
const newString = inputString.split('').map(char => {
2121
// Get a character code by the use charCodeAt method.
2222
const presentCharCode = char.charCodeAt()
23-
// If the character code lies between 97 to 122 it means they are in the lower case so convert it.
23+
// If the character code lies between 97 to 122, it means they are in the lowercase so convert it.
2424
if (presentCharCode >= 97 && presentCharCode <= 122) {
2525
// Convert the case by use of the above explanation.
2626
return String.fromCharCode(presentCharCode - 32)
@@ -32,4 +32,4 @@ const UpperCaseConversion = (inputString) => {
3232
return newString.join('')
3333
}
3434

35-
module.exports = UpperCaseConversion
35+
export { upperCaseConversion }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { upperCaseConversion } from '../UpperCaseConversion'
2+
3+
describe(('Test the upperCaseConversion function'), () => {
4+
it('should return an empty string when the input is an empty string', () => {
5+
expect(upperCaseConversion('')).toEqual('')
6+
})
7+
8+
it('should return an all-uppercase string when input is an all-uppercase string', () => {
9+
expect(upperCaseConversion('ALLUPPERCASE')).toEqual('ALLUPPERCASE')
10+
})
11+
12+
it('should return an all-uppercase string when input is an all-uppercase string with spaces', () => {
13+
expect(upperCaseConversion('ALL UPPERCASE')).toEqual('ALL UPPERCASE')
14+
})
15+
16+
it('should return an all-uppercase string when input is an all-uppercase string with punctuation', () => {
17+
expect(upperCaseConversion('ALL UPPER-CASE!')).toEqual('ALL UPPER-CASE!')
18+
})
19+
20+
it('should return an all-uppercase string when input is an all-lowercase string', () => {
21+
expect(upperCaseConversion('lowercaseinput')).toEqual('LOWERCASEINPUT')
22+
})
23+
24+
it('should return an all-uppercase string when input is an all-lowercase string with spaces', () => {
25+
expect(upperCaseConversion('lowercase input')).toEqual('LOWERCASE INPUT')
26+
})
27+
28+
it('should return an all-uppercase string when input is an all-lowercase string with punctuation', () => {
29+
expect(upperCaseConversion('lower-case, input.')).toEqual('LOWER-CASE, INPUT.')
30+
})
31+
32+
it('should return an all-uppercase string when input is an mixed-case string', () => {
33+
expect(upperCaseConversion('mixeDCaSeINPuT')).toEqual('MIXEDCASEINPUT')
34+
})
35+
36+
it('should return an all-uppercase string when input is an mixed-case string with spaces', () => {
37+
expect(upperCaseConversion('mixeD CaSe INPuT')).toEqual('MIXED CASE INPUT')
38+
})
39+
40+
it('should return an all-uppercase string when input is an mixed-case string with punctuation', () => {
41+
expect(upperCaseConversion('mixeD-CaSe INPuT!')).toEqual('MIXED-CASE INPUT!')
42+
})
43+
})

0 commit comments

Comments
 (0)