From 0c97c61c79f15a4036aa7d44267d31ece0b62647 Mon Sep 17 00:00:00 2001 From: Peter Garrow Date: Sat, 26 Oct 2019 22:25:39 -0600 Subject: [PATCH] Add unit test for all-words-in-trie --- .../all-words-in-trie.test.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js diff --git a/src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js b/src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js new file mode 100644 index 00000000..dbb7d926 --- /dev/null +++ b/src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js @@ -0,0 +1,20 @@ +const Trie = require("../index"); +const allWordsFromTrie = require("."); + +describe("Find all words in Trie", () => { + let trie = new Trie(); + const words = ["bed", "ball", "apple", "java", "javascript", "bed"]; + + it("Should return an empty array when null is passed in", () => { + expect(allWordsFromTrie(null)).toEqual([]); + }); + + it("Should return an empty array when trie is empty", () => { + expect(allWordsFromTrie(trie.root)).toEqual([]); + }); + + it("Should return all words in the trie", () => { + words.forEach(word => trie.insert(word)); + expect(allWordsFromTrie(trie.root).sort()).toEqual(words.sort()); + }); +});