Skip to content

Add Unit Test For - Trie search string #106 #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/_DataStructures_/Trees/Trie/Trie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const Trie = require('./index');

describe('Data Structure : Trie', () => {
it('Should be class', () => {
expect(typeof Trie.prototype.constructor).toEqual('function');
});

describe('Trie', () => {
let newTrie;
beforeEach(() => {
newTrie = new Trie();
});

it('Should return false when search is called without a key', () => {
const result = newTrie.search();
expect(result).toEqual(false);
});

it('Should return false when insert is called without a key', () => {
const result = newTrie.insert();
expect(result).toEqual(false);
});

it('Should return true when insert is called with a key', () => {
const result = newTrie.insert('dflkghik');
const newResult = newTrie.insert('Lorem Ipsum');
expect(result).toEqual(true);
expect(newResult).toEqual(true);
});

it('Should return false when search is called without a key', () => {
const result = newTrie.search();
expect(result).toEqual(false);
});
Comment on lines +31 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate


it('Should return false when searched for a key which is not yet added', () => {
const result = newTrie.search('abc');
expect(result).toEqual(false);
});
Comment on lines +35 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate


it('Should return true when searched for a key which present in trie', () => {
const value = 'abc';
newTrie.insert(value);
newTrie.insert('dflkghik');
newTrie.insert('Lorem Ipsum');
const result = newTrie.search(value);
const newResult = newTrie.search('dflkghik');
const loremIpsumResult = newTrie.search('Lorem Ipsum');
expect(result).toEqual(true);
expect(newResult).toEqual(true);
expect(loremIpsumResult).toEqual(true);
});

it('Should return the index of the Character', () => {
const result = newTrie.getIndexOfChar('a');
const newResult = newTrie.getIndexOfChar('A');
expect(result).toEqual(0);
expect(newResult).toEqual(-32);
});
});
});