Skip to content

Commit

Permalink
[build] Unit Tests
Browse files Browse the repository at this point in the history
- created all required unit tests with jests for the package. all
  critical methods were covered in these tests
- removed/corrected some methods in the package
  • Loading branch information
sricharankrishnan committed Feb 4, 2024
1 parent 0206833 commit efa2393
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 17 deletions.
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ var Vowelz = /*#__PURE__*/function () {

/* sets all vowels to upper case */
}, {
key: "setAllVowelsToUppercase",
value: function setAllVowelsToUppercase(arg) {
key: "setAllVowelsToUpperCase",
value: function setAllVowelsToUpperCase(arg) {
var $this = this;
if (!$this.checkIfPropIsString(arg)) {
throw new Error("Needed argument to be of type string but is not: ".concat(arg));
Expand All @@ -110,8 +110,8 @@ var Vowelz = /*#__PURE__*/function () {

/* get how many vowels are there in a string value */
}, {
key: "getCount",
value: function getCount(arg) {
key: "getTotalCount",
value: function getTotalCount(arg) {
var $this = this;
if (!$this.checkIfPropIsString(arg)) {
throw new Error("Needed argument to be of type string but is not: ".concat(arg));
Expand Down Expand Up @@ -158,7 +158,7 @@ var Vowelz = /*#__PURE__*/function () {
throw new Error("Needed argument to be of type string but is not: ".concat(arg));
return;
}
var uniqueVowels = new Set(arg.match(/[aeiou]/gi));
var uniqueVowels = new Set(arg.toLowerCase().match(/[aeiou]/g));
return uniqueVowels.size;
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vowelz",
"version": "1.1.3",
"version": "1.2.4",
"description": "A JavaScript library for efficient manipulation of vowels within strings. Count, transform case, extract positions, and perform various operations on vowels with ease. Enhance your text processing and string transformations using Vowelz.",
"main": "index.js",
"homepage": "https://github.com/sricharankrishnan/vowelz",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Vowelz {
}

/* sets all vowels to upper case */
setAllVowelsToUppercase(arg) {
setAllVowelsToUpperCase(arg) {
var $this = this;
if (!$this.checkIfPropIsString(arg)) {
throw new Error(`Needed argument to be of type string but is not: ${arg}`);
Expand All @@ -88,7 +88,7 @@ class Vowelz {
}

/* get how many vowels are there in a string value */
getCount(arg) {
getTotalCount(arg) {
var $this = this;
if (!$this.checkIfPropIsString(arg)) {
throw new Error(`Needed argument to be of type string but is not: ${arg}`);
Expand Down
12 changes: 6 additions & 6 deletions tests/accepts-only-string-arg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ describe("Vowelz - Methods Accepts Only String Args", () => {
}).toThrow();
});

test("getCount() - accepts only string arg", () => {
test("getTotalCount() - accepts only string arg", () => {
expect(() => {
myVowelz.getCount(stringArg);
myVowelz.getTotalCount(stringArg);
}).not.toThrow();

expect(() => {
myVowelz.getCount(nonStringArg);
myVowelz.getTotalCount(nonStringArg);
}).toThrow();
});

test("setAllVowelsToUppercase() - accepts only string arg", () => {
test("setAllVowelsToUpperCase() - accepts only string arg", () => {
expect(() => {
myVowelz.setAllVowelsToUppercase(stringArg);
myVowelz.setAllVowelsToUpperCase(stringArg);
}).not.toThrow();

expect(() => {
myVowelz.setAllVowelsToUppercase(nonStringArg);
myVowelz.setAllVowelsToUpperCase(nonStringArg);
}).toThrow();
});

Expand Down
54 changes: 54 additions & 0 deletions tests/count-all-vowels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* app imports */
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz - countAllVowels method", () => {
let myVowelz = null;

beforeAll(() => {
myVowelz = new Vowelz();
});

afterAll(() => {
myVowelz = null;
});

test("returns all vowels as 'zero' count if input string is empty", () => {
const input = "";
const output = {
a: 0,
e: 0,
i: 0,
o: 0,
u: 0
};
const result = myVowelz.countAllVowels(input);
expect(result).toEqual(output);
});

test("returns all vowels as 'zero' count if there are no vowels in input string", () => {
const input = "My Rhythms fly. My rhythms cry.";
const output = {
a: 0,
e: 0,
i: 0,
o: 0,
u: 0
};
const result = myVowelz.countAllVowels(input);
expect(result).toEqual(output);
});

test("returns the correct count of all vowels from an input string", () => {
const input = "Hello World. This is a test message";
const output = {
a: 2,
e: 4,
i: 2,
o: 2,
u: 0
};
const result = myVowelz.countAllVowels(input);
expect(result).toEqual(output);
});
});
59 changes: 59 additions & 0 deletions tests/extract-all-vowels-from-string.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* app imports */
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz - extractAllVowelsFromString method", () => {
let myVowelz = null;

beforeAll(() => {
myVowelz = new Vowelz();
});

afterAll(() => {
myVowelz = null;
});

test("will also extract duplicate strings from the input", () => {
const input = "Pool Table";
const output = ["o", "o", "a", "e"];
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toEqual(output);
});

test("preserves the order of vowels in the input string", () => {
const input = "Beautiful World";
const output = ["e", "a", "u", "i", "u", "o"];
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toEqual(output);
});

test("gives an empty array output if no vowels are present in the input", () => {
const input = "1234567890!@#$%^&*()~_+";
const output = [];
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toHaveLength(0);
expect(result).toEqual(output);
});

test("returns an empty array if the input string is empty", () => {
const input = "";
const output = [];
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toHaveLength(0);
expect(result).toEqual(output);
});

test("the ouput array of vowels is of the right length", () => {
const input = "Hello World";
const output = 3;
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toHaveLength(output);
});

test("correct extracts all vowels from a given string", () => {
const input = "Hello, World! This is a test string.";
const output = ["e", "o", "o", "i", "i", "a", "e", "i"];
const result = myVowelz.extractAllVowelsFromString(input);
expect(result).toEqual(output);
});
});
50 changes: 50 additions & 0 deletions tests/get-position-of-vowels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* app imports */
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz - getPositionsOfVowels method", () => {
let myVowelz = null;

beforeAll(() => {
myVowelz = new Vowelz();
});

afterAll(() => {
myVowelz = null;
});

test("provides the correct result even when are duplicate vowels", () => {
const input = "Pool Table";
const output = [1, 2, 6, 9];
const result = myVowelz.getPositionsOfVowels(input);
expect(result).toEqual(output);
});

test("result prevserves order of indices for vowels in input string", () => {
const input = "hello world";
const output = [1, 4, 7];
const result = myVowelz.getPositionsOfVowels(input);
expect(result).toEqual(output);
});

test("no vowels in string: results in empty array", () => {
const input = "~!@#$%^&*()_+1234567890";
const output = [];
const result = myVowelz.getPositionsOfVowels(input);
expect(result).toEqual(output);
});

test("empty string input: results in empty array", () => {
const input = "";
const output = [];
const result = myVowelz.getPositionsOfVowels(input);
expect(result).toEqual(output);
});

test("returns an array of numbers, which are indices of vowels in input", () => {
const input = 'Hello, World! This is a test string.';
const output = [1, 4, 8, 16, 19, 22, 25, 32];
const result = myVowelz.getPositionsOfVowels(input);
expect(result).toEqual(output);
});
});
49 changes: 49 additions & 0 deletions tests/get-total-count-of-vowels.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* app imports */
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz - getTotalCount method", () => {
let myVowelz = null;

beforeAll(() => {
myVowelz = new Vowelz();
});

afterAll(() => {
myVowelz = null;
});

test("result includes duplicate vowels present in input string", () => {
const input = "Pool Table";
const output = 4;
const result = myVowelz.getTotalCount(input);
expect(result).toBe(output);
});

test("will return 'zero' if there are no vowels present", () => {
const input = "";
const output = 0;
const result = myVowelz.getTotalCount(input);
expect(result).toBe(output);
});

test("will return 'zero' if input string is empty", () => {
const input = "";
const output = 0;
const result = myVowelz.getTotalCount(input);
expect(result).toBe(output);
});

test("evaluates and returns correct number of vowels in an input string", () => {
const input = "Hello, World! This is a test string.";
const output = 8;
const result = myVowelz.getTotalCount(input);
expect(result).toBe(output);
});

test("return a number type when caluclating total count of vowels", () => {
const input = "Hello World!";
const result = myVowelz.getTotalCount(input);
expect(typeof result).toBe("number");
});
});
2 changes: 1 addition & 1 deletion tests/remove-all-vowels-from-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz removeAllVowelsFromString method", () => {
describe("Vowelz - removeAllVowelsFromString method", () => {
let myVowelz = null;

beforeAll(() => {
Expand Down
46 changes: 46 additions & 0 deletions tests/replace-vowels-with-character.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* app imports */
import Vowelz from "../src/index.js";

/* t-suite */
describe("Vowelz - replaceVowelsWithCharacter method", () => {
let myVowelz = null;

beforeAll(() => {
myVowelz = new Vowelz();
});

afterAll(() => {
myVowelz = null;
});

test("throws an error if 'character arg' length is greater than 1", () => {
function demoWrapper() {
myVowelz.replaceVowelsWithCharacter("Hello World", "**");
}
expect(demoWrapper).toThrow();
});

test("will not modify the input string if there are no vowels", () => {
const character = "&";
const input = "1234567890~!@#$%^&*()_+";
const output = "1234567890~!@#$%^&*()_+";
const results = myVowelz.replaceVowelsWithCharacter(input, character);
expect(results).toBe(output);
});

test("will return an empty string if the input string is empty", () => {
const character = "&";
const input = "";
const output = "";
const results = myVowelz.replaceVowelsWithCharacter(input, character);
expect(results).toBe(output);
});

test("correctly replaces vowels with a given character", () => {
const character = "&";
const input = "The sky is blue";
const output = "Th& sky &s bl&&";
const results = myVowelz.replaceVowelsWithCharacter(input, character);
expect(results).toBe(output);
});
});
Loading

0 comments on commit efa2393

Please sign in to comment.