spanish-quizzer

An app to quiz you on Spanish vocabulary and verb conjugations
git clone https://git.ashermorgan.net/spanish-quizzer/
Log | Files | Refs | README

commit 159ddd95c3dfe7873ef8e78271f4b1a936e08d2b
parent 754f33d31828a4c3bc204301617927da973b728d
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date:   Mon,  5 Oct 2020 14:52:02 -0700

Merge pull request #21 from AsherMorgan/add-filters

Add more filters.
Diffstat:
MREADME.md | 26++++++++++++++++++++------
Mcss/settings.css | 43+++++++++++++++++++++++++++++++------------
Mindex.html | 18++++++++++++++++--
Mjs/home.js | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Mjs/settings.js | 295++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mtests/test.app.js | 121++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Mtests/test.settings.js | 645++++++++++++++++++++++++++++++++++++++++++-------------------------------------
7 files changed, 735 insertions(+), 485 deletions(-)

diff --git a/README.md b/README.md @@ -33,23 +33,25 @@ Spanish-Quizzer comes with many vocabulary sets that can be filtered by word typ - Health (La Salud) ## Vocabulary Filters -Spanish-Quizzer comes with many vocabulary filters. Not all filters may be used on every vocab set. -- Language - - Spanish to English +The following filters can be used on vocabulary sets: +- Language filters + - Enlish to and from Spanish - English to Spanish -- Word Type - - Noun + - Spanish to English +- Word type filters - Adjective + - Noun - Verb ## Verb Filters +The following filters can be used on verb conjugations: - Tense filters - All tenses - Present Participles - Present Tense - Preterite Tense - Imperfect Tense -- Regularity filters +- Conjugation type filters - All Conjugations - Conjugations of reflexive verbs - Regular Conjugations @@ -57,3 +59,15 @@ Spanish-Quizzer comes with many vocabulary filters. Not all filters may be used - Stem Changing Conjugations - Orthographic Conjugations - Irregular Conjugations +- Subject filters + - All subjects + - Yo + - Tú + - Él + - Nosotros + - Ellos +- Direction filters + - English infinitives to Spanish conjugations + - Spanish infinitives to Spanish conjugations + - Spanish conjugations to English infinitives + - Spanish conjugations to Spanish infinitives diff --git a/css/settings.css b/css/settings.css @@ -55,7 +55,7 @@ -/* Start/Resume Button */ +/* Start/Resume Buttons */ #settingButtons { margin-top: 20px; margin-bottom: 10px; @@ -66,6 +66,16 @@ font-size: 18px; margin: 0px 5px; } +@media only screen and (max-width: 510px) { + /* Expand Start/Resume buttons */ + #settingButtons { + width: calc(100% - 10px); + } + #settingButtons button { + width: calc(50% - 15px); + height: 50px; + } +} @@ -76,27 +86,36 @@ -@media only screen and (max-width: 300px) { - /* Filters */ - #vocabSettings, #verbSettings { +/* Conjugation settings on mobile devices */ +@media only screen and (max-width: 510px) { + #verbSettings { width: calc(100% - 20px); } - .filter { + #verbSettings .filter { width: 100%; margin: 10px auto; } - .filter select, .filter button { + #verbSettings .filter select, #verbSettings .filter button { width: 100%; height: 30px; margin: 3px 0px; } +} - /* Start/Resume Buttons */ - #settingButtons { - width: calc(100% - 10px); + + +/* Vocab settings on mobile devices */ +@media only screen and (max-width: 350px) { + #vocabSettings { + width: calc(100% - 20px); } - #settingButtons button { - width: calc(50% - 15px); - height: 50px; + #vocabSettings .filter { + width: 100%; + margin: 10px auto; + } + #vocabSettings .filter select, #vocabSettings s.filter button { + width: 100%; + height: 30px; + margin: 3px 0px; } } diff --git a/index.html b/index.html @@ -61,6 +61,15 @@ <select v-model="filter.type"> <option v-for="(available, type) in getTenseTypes(index)" :disabled="!available">{{ type }}</option> </select> + <select v-model="filter.subject"> + <option v-for="(available, subject) in getTenseSubjects(index)" :disabled="!available">{{ subject }}</option> + </select> + <select v-model="filter.direction"> + <option>Eng. → Conj.</option> + <option>Esp. → Conj.</option> + <option>Conj. → Eng.</option> + <option>Conj. → Esp.</option> + </select> <button class="itemRemove" @click="RemoveVerbFilter(index);">╳</button> </div> </div> @@ -101,8 +110,13 @@ <option>Health</option> </optgroup> </select> - <select class="vocabSetFilter" v-model="filter.type"> - <option v-for="type in getSetFilters(index)" >{{ type }}</option> + <select v-model="filter.type"> + <option v-for="(available, type) in getSetFilters(index)" :disabled="!available">{{ type }}</option> + </select> + <select v-model="filter.direction"> + <option>Eng. ↔ Esp.</option> + <option>Eng. → Esp.</option> + <option>Esp. → Eng.</option> </select> <button class="itemRemove" @click="RemoveVocabFilter(index);">╳</button> </div> diff --git a/js/home.js b/js/home.js @@ -50,7 +50,7 @@ function loadVue() { * Add a verb filter on the settings page. */ AddVerbFilter: function() { - this.verbFilters.push({"tense":"All Tenses", "type":"All Types"}); + this.verbFilters.push({tense:"All Tenses", type:"All Types", subject:"All Subjects", direction:"Eng. → Conj."}); }, /** @@ -66,7 +66,7 @@ function loadVue() { * Add a vocab filter on the settings page. */ AddVocabFilter: function() { - this.vocabFilters.push({"set":"Verbs", "type":"All Definitions"}); + this.vocabFilters.push({set:"Verbs", type:"All Types", direction:"Eng. ↔ Esp."}); }, /** @@ -115,40 +115,84 @@ function loadVue() { }, /** + * Get the subject filters available for a verb filter. + * @param {Number} index - The index of the verb filter. + * @returns {object} - An object with boolean properties for each subject filter. + */ + getTenseSubjects: function(index) { + // Set default filters + let filters = {"All Subjects":true, "Yo":true, "Tú":true, "Él":true, "Nosotros":true, "Ellos":true} + + if (this.verbFilters[index].tense === "Present Participles") { + // Override filters + filters["Yo"] = false; + filters["Tú"] = false; + filters["Él"] = false; + filters["Nosotros"] = false; + filters["Ellos"] = false; + + // Reset subject + this.verbFilters[index].subject = "All Subjects"; + } + + // Return filters + return filters; + }, + + /** * Get the filters available for a vocab Set. * @param {Number} index - The index of the vocab filter. * @returns {Array} - An array containing available filters. */ getSetFilters: function(index) { // Get filter options - var filters = []; + let filters = {"All Types":true, "Adjectives":true, "Nouns":true, "Verbs":true} switch(this.vocabFilters[index].set) { case "Verbs": - filters = ["All Definitions", "Spanish Infinitives", "English Infinitives", "Reverse Conjugations"]; + filters["Adjectives"] = false; + filters["Nouns"] = false; + filters["Verbs"] = false; break; case "Adjectives": + filters["Nouns"] = false; + filters["Verbs"] = false; + break; + case "Adverbs": + filters["Adjectives"] = false; + filters["Nouns"] = false; + filters["Verbs"] = false; + break; + case "Prepositions": case "Transitions": + case "Questions": + filters["Adjectives"] = false; + filters["Nouns"] = false; + filters["Verbs"] = false; + break; + case "Colors": + filters["Nouns"] = false; + filters["Verbs"] = false; + break; + case "Days": case "Months": - case "Questions": - filters = ["All Definitions", "English to Spanish", "Spanish to English"]; + filters["Adjectives"] = false; + filters["Verbs"] = false; break; - + case "Weather": case "Professions": - filters = ["All Definitions", "English to Spanish", "Spanish to English", - "Nouns", "Verbs"]; + filters["Adjectives"] = false; break; case "Family": case "Clothes": - filters = ["All Definitions", "English to Spanish", "Spanish to English", - "Nouns", "Adjectives"]; + filters["Verbs"] = false; break; case "Nature": @@ -156,14 +200,12 @@ function loadVue() { case "Vacation": case "Childhood": case "Health": - filters = ["All Definitions", "English to Spanish", "Spanish to English", - "Nouns", "Verbs", "Adjectives"]; break; } // Reset type if needed - if (!filters.includes(this.vocabFilters[index].type)) { - this.vocabFilters[index].type = filters[0]; + if (!filters[this.vocabFilters[index].type]) { + this.vocabFilters[index].type = "All Types"; } // Return filters diff --git a/js/settings.js b/js/settings.js @@ -9,7 +9,7 @@ function CreateSession() { for (let filter of app.vocabFilters) { // Add filtered set - app.prompts.push(...ApplyVocabFilter(Sets[filter.set], filter.type)); + app.prompts.push(...ApplyVocabFilter(Sets[filter.set], filter.type, filter.direction)); } // Shuffle prompts @@ -133,87 +133,51 @@ function StartSession() { /** * Filter a vocab set. * @param {Array} vocabSet - The vocab set to filter. - * @param {String} name - The name of the filter. + * @param {String} type - The word type filter. + * @param {String} direction - The direction filter. + * @returns {Array} - A list of prompts. */ -function ApplyVocabFilter(vocabSet, name) { - // Declare variables - var io; // Format: [[<output index>, <input index>]] - var value; // Format: [[<index>, [<values>], exclude?]] - - // Get filter - switch (name) { - case "All Definitions": - io = [[0,1], [1,0]]; - value = []; - break; - - case "Spanish Infinitives": - case "English to Spanish": - io = [[0,1]]; - value = []; - break; - - case "English Infinitives": - case "Spanish to English": - io = [[1,0]]; - value = []; - break; - - case "Reverse Conjugations": - io = [[3,0], [5,0], [6,0], [7,0], [8,0], [9,0], [11,0], [12,0], [13,0], [14,0], [15,0], [17,0], [18,0], [19,0], [20,0], [21,0]]; - value = []; +function ApplyVocabFilter(terms, type, direction) { + // Get type regex filter + let regularity; + switch (type.toLowerCase()) { + case "adjectives": + regularity = "Adjective"; break; - - case "Nouns": - io = [[0,1], [1,0]]; - value = [[2, ["Noun"], false]]; + case "nouns": + regularity = "Noun"; break; - case "Verbs": - io = [[0,1], [1,0]]; - value = [[2, ["Verb"], false]]; + case "verbs": + regularity = "Verb"; break; - case "Adjectives": - io = [[0,1], [1,0]]; - value = [[2, ["Adjective"], false]]; + case "all types": + regularity = ".*"; break; - default: - io = []; - value = []; - break; + throw `Unrecognized filter: ${type}.`; } - // Filter terms by value - var vSet = vocabSet.slice(1); // Format: same as vocabSet but without headers - for (var i = 0; i < value.length; i++) { - for (var j = 0; j < vSet.length; j++) { - if (value[i][2]) { - // Exclude values - if (value[i][1].includes(vSet[j][value[i][0]])) { - vSet.splice(j, 1); // Remove item - j--; // Adjust for the removal of an item - } + // Filter terms + let results = []; // Format: [[<output label>, <output>, <input label>, <input>]] + for (let term of terms.slice(1)) { + // Check against filters + if (term[2].match(regularity)) { + if (direction === "Eng. ↔ Esp.") { + results.push([terms[0][0], term[0], terms[0][1], term[1]]); + results.push([terms[0][1], term[1], terms[0][0], term[0]]); + } + else if (direction === "Eng. → Esp.") { + results.push([terms[0][0], term[0], terms[0][1], term[1]]); + } + else if (direction === "Esp. → Eng.") { + results.push([terms[0][1], term[1], terms[0][0], term[0]]); } else { - // Include values - if (!value[i][1].includes(vSet[j][value[i][0]])) { - vSet.splice(j, 1); // Remove item - j--; // Adjust for the removal of an item - } + throw `Unrecognized direction: ${direction}.`; } } } - - // Filter terms by input/output - var ioSet = []; // Format: [<output type>, <output>, <input type>, <input>] - for (var i = 0; i < io.length; i++) { - for (var j = 0; j < vSet.length; j++) { - ioSet.push([vocabSet[0][io[i][0]], vSet[j][io[i][0]], vocabSet[0][io[i][1]], vSet[j][io[i][1]]]); - } - } - - // Return filtered set - return ioSet; + return results; } @@ -221,99 +185,170 @@ function ApplyVocabFilter(vocabSet, name) { /** * Filter verb conjugations. * @param {Array} terms - The list of verb conjugations to filter. - * @param {Array} filterInfo - A list of filters, + * @param {Array} filterInfo - A list of filters. + * @returns {Array} - A list of prompts. */ function ApplyVerbFilter(terms, filterInfo) { - // Create filters - let filters = []; // Format: [{outputIndex:0, inputIndex:0, filterIndex:0, filterValue:"regex"}] - for (let config of filterInfo) { - // Get regularity - let regularity; - switch (config.type.toLowerCase()) { + // Expand "All Tenses" filters + let filters = []; // Format: [{tense:"specific tense", subject:"specific subject", type:"regex"}] + for (let filter of filterInfo) { + if (filter.tense.toLowerCase() == "all tenses") { + filters.push({ tense: "present participles", type: filter.type, subject: filter.subject, direction: filter.direction }); + filters.push({ tense: "present tense", type: filter.type, subject: filter.subject, direction: filter.direction }); + filters.push({ tense: "preterite tense", type: filter.type, subject: filter.subject, direction: filter.direction }); + filters.push({ tense: "imperfect tense", type: filter.type, subject: filter.subject, direction: filter.direction }); + } + else { + filters.push({ tense: filter.tense.toLowerCase(), type: filter.type, subject: filter.subject, direction: filter.direction }); + } + } + + // Expand "All Subjects" filters + for (let filter of filters) { + if (filter.subject.toLowerCase() == "all subjects" && filter.tense != "present participles") { + filter.subject = "yo"; + filters.push({ tense: filter.tense, type: filter.type, subject: "tú", direction: filter.direction }); + filters.push({ tense: filter.tense, type: filter.type, subject: "él", direction: filter.direction }); + filters.push({ tense: filter.tense, type: filter.type, subject: "nosotros", direction: filter.direction }); + filters.push({ tense: filter.tense, type: filter.type, subject: "ellos", direction: filter.direction }); + } + else { + filter.subject = filter.subject.toLowerCase(); + } + } + + // Replace regularities with regex filters + for (let filter of filters) { + switch (filter.type.toLowerCase()) { case "regular": - regularity = "Regular"; + filter.type = "Regular"; break; case "reflexive": - regularity = "Reflexive"; + filter.type = "Reflexive"; break; case "irregular": - regularity = "Irregular"; + filter.type = "Irregular"; break; - case "stem-changing": case "stem changing": - regularity = "Stem.?Changing"; + filter.type = "Stem.?Changing"; break; case "orthographic": - regularity = "Orthographic"; + filter.type = "Orthographic"; break; - case "non-regular": - case "non regular": case "nonregular": - regularity = "Irregular|Stem.?Changing|Orthographic"; + filter.type = "Irregular|Stem.?Changing|Orthographic"; + break; + case "all types": + filter.type = ".*"; break; default: - case "all": - regularity = ".*"; + throw `Unrecognized filter: ${filter.type}.`; } + } - // Create filter - switch (config.tense.toLowerCase()) { - case "present participle": + // Create io filters + let ioFilters = []; // Format: [{outputIndex:0, inputIndex:0, filterIndex:0, filterValue:"regex"}] + for (let filter of filters) { + // Get output index + let outputIndex; + if (filter.direction.toLowerCase().includes("eng")) { + outputIndex = 0; + } + else if (filter.direction.toLowerCase().includes("esp")) { + outputIndex = 1; + } + + // Get input index and filter index + let inputIndex; + let filterIndex; + switch (filter.tense) { case "present participles": - filters.push({outputIndex:0, inputIndex:3, filterIndex:2, filterValue:regularity}); + filterIndex = 2; + inputIndex = 3; break; - case "present": case "present tense": - filters.push({outputIndex:0, inputIndex:5, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:6, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:7, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:8, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:9, filterIndex:4, filterValue:regularity}); + filterIndex = 4; + switch (filter.subject) { + case "yo": + inputIndex = 5; + break; + case "tú": + inputIndex = 6; + break; + case "él": + inputIndex = 7; + break; + case "nosotros": + inputIndex = 8; + break; + case "ellos": + inputIndex = 9; + break; + default: + throw `Unrecognized subject: ${filter.subject}.`; + } break; - case "preterite": case "preterite tense": - filters.push({outputIndex:0, inputIndex:11, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:12, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:13, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:14, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:15, filterIndex:10, filterValue:regularity}); + filterIndex = 10; + switch (filter.subject) { + case "yo": + inputIndex = 11; + break; + case "tú": + inputIndex = 12; + break; + case "él": + inputIndex = 13; + break; + case "nosotros": + inputIndex = 14; + break; + case "ellos": + inputIndex = 15; + break; + default: + throw `Unrecognized subject: ${filter.subject}.`; + } break; - case "imperfect": case "imperfect tense": - filters.push({outputIndex:0, inputIndex:17, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:18, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:19, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:20, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:21, filterIndex:16, filterValue:regularity}); + filterIndex = 16; + switch (filter.subject) { + case "yo": + inputIndex = 17; + break; + case "tú": + inputIndex = 18; + break; + case "él": + inputIndex = 19; + break; + case "nosotros": + inputIndex = 20; + break; + case "ellos": + inputIndex = 21; + break; + default: + throw `Unrecognized subject: ${filter.subject}.`; + } break; default: - case "all": - filters.push({outputIndex:0, inputIndex:3, filterIndex:2, filterValue:regularity}); + throw `Unrecognized tense: ${filter.tense}.`; + } - filters.push({outputIndex:0, inputIndex:5, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:6, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:7, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:8, filterIndex:4, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:9, filterIndex:4, filterValue:regularity}); - - filters.push({outputIndex:0, inputIndex:11, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:12, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:13, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:14, filterIndex:10, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:15, filterIndex:10, filterValue:regularity}); - - filters.push({outputIndex:0, inputIndex:17, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:18, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:19, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:20, filterIndex:16, filterValue:regularity}); - filters.push({outputIndex:0, inputIndex:21, filterIndex:16, filterValue:regularity}); - break; + // Create filter + if (filter.direction.toLowerCase().startsWith("conj")) { + // Swap input and output + ioFilters.push({outputIndex:inputIndex, inputIndex:outputIndex, filterIndex:filterIndex, filterValue:filter.type}) + } + else { + ioFilters.push({outputIndex:outputIndex, inputIndex:inputIndex, filterIndex:filterIndex, filterValue:filter.type}) } } // Filter terms let results = []; // Format: [[<output label>, <output>, <input label>, <input>]] - for (let filter of filters) { + for (let filter of ioFilters) { // Iterate over terms (minus headers) for (let term of terms.slice(1)) { // Check against filters diff --git a/tests/test.app.js b/tests/test.app.js @@ -87,6 +87,8 @@ describe("App", function() { expect(app.verbFilters.length).to.equal(1); expect(app.verbFilters[0]["tense"]).to.equal("All Tenses"); expect(app.verbFilters[0]["type"]).to.equal("All Types"); + expect(app.verbFilters[0]["subject"]).to.equal("All Subjects"); + expect(app.verbFilters[0]["direction"]).to.equal("Eng. → Conj."); }); }); @@ -122,7 +124,8 @@ describe("App", function() { // Assert filter added expect(app.vocabFilters.length).to.equal(1); expect(app.vocabFilters[0]["set"]).to.equal("Verbs"); - expect(app.vocabFilters[0]["type"]).to.equal("All Definitions"); + expect(app.vocabFilters[0]["type"]).to.equal("All Types"); + expect(app.vocabFilters[0]["direction"]).to.equal("Eng. ↔ Esp."); }); }); @@ -231,6 +234,86 @@ describe("App", function() { }); }); + describe("GetTenseSubjects method", function() { + it("Should be correct for All Tenses", function() { + // Initialize filters + app.verbFilters = [ + {"tense":"All Types", "type":"All Types"} + ] + + // Get filters + let filters = app.getTenseSubjects(0); + + // Assert filters are correct + expect(filters["All Subjects"]).to.equal(true); + expect(filters["Yo"]).to.equal(true); + expect(filters["Tú"]).to.equal(true); + expect(filters["Él"]).to.equal(true); + expect(filters["Nosotros"]).to.equal(true); + expect(filters["Ellos"]).to.equal(true); + }); + + it("Should be correct for Present Participles", function() { + // Initialize filters + app.verbFilters = [ + {"tense":"Present Participles", "subject":"All Subjects", "type":"All Types"} + ] + + // Get filters + let filters = app.getTenseSubjects(0); + + // Assert filters are correct + expect(filters["All Subjects"]).to.equal(true); + expect(filters["Yo"]).to.equal(false); + expect(filters["Tú"]).to.equal(false); + expect(filters["Él"]).to.equal(false); + expect(filters["Nosotros"]).to.equal(false); + expect(filters["Ellos"]).to.equal(false); + }); + + it("Should change selection if not available", function() { + // Initialize filters + app.verbFilters = [ + {"tense":"Present Participles", "subject":"Yo", "type":"All Types"} + ] + + // Get filters + let filters = app.getTenseSubjects(0); + + // Assert filters are correct + expect(filters["All Subjects"]).to.equal(true); + expect(filters["Yo"]).to.equal(false); + expect(filters["Tú"]).to.equal(false); + expect(filters["Él"]).to.equal(false); + expect(filters["Nosotros"]).to.equal(false); + expect(filters["Ellos"]).to.equal(false); + + // Assert selection changed + expect(app.verbFilters[0]["subject"]).to.equal("All Subjects"); + }); + + it("Should not change selection if available", function() { + // Initialize filters + app.verbFilters = [ + {"tense":"Preterite Tense", "subject":"Yo", "type":"All Types"} + ] + + // Get filters + let filters = app.getTenseSubjects(0); + + // Assert filters are correct + expect(filters["All Subjects"]).to.equal(true); + expect(filters["Yo"]).to.equal(true); + expect(filters["Tú"]).to.equal(true); + expect(filters["Él"]).to.equal(true); + expect(filters["Nosotros"]).to.equal(true); + expect(filters["Ellos"]).to.equal(true); + + // Assert selection not changed + expect(app.verbFilters[0]["subject"]).to.equal("Yo"); + }); + }); + describe("GetSetFilters method", function() { it("Should be correct for Verbs", function() { // Initialize filters @@ -239,14 +322,13 @@ describe("App", function() { ] // Get filters - let actual = app.getSetFilters(0); + let filters = app.getSetFilters(0); // Assert filters are correct - let expected = ["All Definitions", "Spanish Infinitives", "English Infinitives", "Reverse Conjugations"]; - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i]).to.equal(expected[i]); - } + expect(filters["All Types"]).to.equal(true); + expect(filters["Adjectives"]).to.equal(false); + expect(filters["Nouns"]).to.equal(false); + expect(filters["Verbs"]).to.equal(false); }); it("Should be correct for sets with 1 type", function() { @@ -256,14 +338,13 @@ describe("App", function() { ] // Get filters - let actual = app.getSetFilters(0); + let filters = app.getSetFilters(0); // Assert filters are correct - let expected = ["All Definitions", "English to Spanish", "Spanish to English"]; - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i]).to.equal(expected[i]); - } + expect(filters["All Types"]).to.equal(true); + expect(filters["Adjectives"]).to.equal(true); + expect(filters["Nouns"]).to.equal(false); + expect(filters["Verbs"]).to.equal(false); }); it("Should change selection if not available", function() { @@ -273,10 +354,14 @@ describe("App", function() { ] // Get filters - app.getSetFilters(0); + let filters = app.getSetFilters(0); // Assert selection changed - expect(app.vocabFilters[0]["type"]).to.equal("All Definitions"); + expect(filters["All Types"]).to.equal(true); + expect(filters["Adjectives"]).to.equal(true); + expect(filters["Nouns"]).to.equal(false); + expect(filters["Verbs"]).to.equal(false); + expect(app.vocabFilters[0]["type"]).to.equal("All Types"); }); it("Should not change selection if available", function() { @@ -286,9 +371,13 @@ describe("App", function() { ] // Get filters - app.getSetFilters(0); + let filters = app.getSetFilters(0); // Assert selection not changed + expect(filters["All Types"]).to.equal(true); + expect(filters["Adjectives"]).to.equal(false); + expect(filters["Nouns"]).to.equal(true); + expect(filters["Verbs"]).to.equal(true); expect(app.vocabFilters[0]["type"]).to.equal("Verbs"); }); }); diff --git a/tests/test.settings.js b/tests/test.settings.js @@ -20,16 +20,10 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "All Definitions"); + let actual = ApplyVocabFilter(vocab, "All Types", "Eng. ↔ Esp."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); it("Should correctly filter vocab for English to Spanish", function() { @@ -41,16 +35,10 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "English to Spanish"); + let actual = ApplyVocabFilter(vocab, "All Types", "Eng. → Esp."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); it("Should correctly filter vocab for Spanish to English", function() { @@ -62,16 +50,10 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "Spanish to English"); + let actual = ApplyVocabFilter(vocab, "All Types", "Esp. → Eng."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); it("Should correctly filter vocab for Nouns", function() { @@ -82,16 +64,10 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "Nouns"); + let actual = ApplyVocabFilter(vocab, "Nouns", "Eng. ↔ Esp."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); it("Should correctly filter vocab for Adjectives", function() { @@ -102,16 +78,10 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "Adjectives"); + let actual = ApplyVocabFilter(vocab, "Adjectives", "Eng. ↔ Esp."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); it("Should correctly filter vocab for Verbs", function() { @@ -122,24 +92,23 @@ describe("Settings", function() { ]; // Filter vocab - let actual = ApplyVocabFilter(vocab, "Verbs"); + let actual = ApplyVocabFilter(vocab, "Verbs", "Eng. ↔ Esp."); // Assert filtered vocab is correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); - it("Should return empty list by default", function() { - // Assert result is empty by default - expect(ApplyVocabFilter(vocab, "test").length).to.equal(0); - expect(ApplyVocabFilter(vocab, "").length).to.equal(0); - expect(ApplyVocabFilter(vocab, 1).length).to.equal(0); - expect(ApplyVocabFilter(vocab, null).length).to.equal(0); + it("Should throw error by default", function() { + // Assert throws error by default + expect(() => ApplyVocabFilter(vocab, "test", "Eng. ↔ Esp.")).to.throw() + expect(() => ApplyVocabFilter(vocab, "", "Eng. ↔ Esp.")).to.throw() + expect(() => ApplyVocabFilter(vocab, 1, "Eng. ↔ Esp.")).to.throw() + expect(() => ApplyVocabFilter(vocab, null, "Eng. ↔ Esp.")).to.throw() + + expect(() => ApplyVocabFilter(vocab, "Verbs", "test")).to.throw() + expect(() => ApplyVocabFilter(vocab, "Verbs", "")).to.throw() + expect(() => ApplyVocabFilter(vocab, "Verbs", "1")).to.throw() + expect(() => ApplyVocabFilter(vocab, "Verbs", null)).to.throw() }); }); @@ -173,38 +142,13 @@ describe("Settings", function() { ]; // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"all"}]); + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); - it("Should correctly filter verbs for Present Participles", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "1A", "1a"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"Present Participles", "type":"all"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter verbs for Present Tense", function() { + it("Should correctly filter verbs for multiple filters", function() { // Initialize expected let expected = [ ["KEY", "key", "2A", "2a"], @@ -212,254 +156,347 @@ describe("Settings", function() { ["KEY", "key", "2C", "2c"], ["KEY", "key", "2D", "2d"], ["KEY", "key", "2E", "2e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"Present Tense", "type":"all"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter verbs for Preterite Tense", function() { - // Initialize expected - let expected = [ ["KEY", "key", "3A", "3a"], ["KEY", "key", "3B", "3b"], ["KEY", "key", "3C", "3c"], ["KEY", "key", "3D", "3d"], ["KEY", "key", "3E", "3e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"Preterite Tense", "type":"all"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter verbs for Imperfect Tense", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "4A", "4a"], - ["KEY", "key", "4B", "4b"], - ["KEY", "key", "4C", "4c"], - ["KEY", "key", "4D", "4d"], - ["KEY", "key", "4E", "4e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"Imperfect Tense", "type":"all"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter regular verbs", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "1A", "1a"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Regular"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter reflexive verbs", function() { - // Initialize expected - let expected = [ ["KEY", "key", "4A", "4a"], ["KEY", "key", "4B", "4b"], ["KEY", "key", "4C", "4c"], ["KEY", "key", "4D", "4d"], ["KEY", "key", "4E", "4e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Reflexive"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter stem changing verbs", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "4A", "4a"], - ["KEY", "key", "4B", "4b"], - ["KEY", "key", "4C", "4c"], - ["KEY", "key", "4D", "4d"], - ["KEY", "key", "4E", "4e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Stem Changing"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter orthographic verbs", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "3A", "3a"], - ["KEY", "key", "3B", "3b"], - ["KEY", "key", "3C", "3c"], - ["KEY", "key", "3D", "3d"], - ["KEY", "key", "3E", "3e"], - ]; - - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Orthographic"}]); - - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } - }); - - it("Should correctly filter irregular verbs", function() { - // Initialize expected - let expected = [ + ["KEY", "key", "2A", "2a"], ["KEY", "key", "2B", "2b"], ["KEY", "key", "2C", "2c"], ["KEY", "key", "2D", "2d"], ["KEY", "key", "2E", "2e"], + + ["4D", "4d", "SPANISH INF", "spanish inf"], ]; // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"irregular"}]); + let actual = ApplyVerbFilter(verbs, [ + { tense:"all tenses", subject:"all subjects", type:"Nonregular", direction:"Eng. => Conj." }, + { tense:"present tense", subject:"all subjects", type:"all types", direction:"Eng. => Conj." }, + { "tense":"all tenses", subject:"nosotros", type:"stem changing", direction:"Conj. => Esp." } + ]); // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + expect(actual).to.have.deep.members(expected); }); - - it("Should correctly filter nonregular verbs", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "2A", "2a"], - ["KEY", "key", "2B", "2b"], - ["KEY", "key", "2C", "2c"], - ["KEY", "key", "2D", "2d"], - ["KEY", "key", "2E", "2e"], - ["KEY", "key", "3A", "3a"], - ["KEY", "key", "3B", "3b"], - ["KEY", "key", "3C", "3c"], - ["KEY", "key", "3D", "3d"], - ["KEY", "key", "3E", "3e"], - ["KEY", "key", "4A", "4a"], - ["KEY", "key", "4B", "4b"], - ["KEY", "key", "4C", "4c"], - ["KEY", "key", "4D", "4d"], - ["KEY", "key", "4E", "4e"], - ]; - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Nonregular"}]); + describe("Tense filters", function() { + it("Should correctly filter verbs for Present Participles", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ]; - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"Present Participles", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter verbs for Present Tense", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "2A", "2a"], + ["KEY", "key", "2B", "2b"], + ["KEY", "key", "2C", "2c"], + ["KEY", "key", "2D", "2d"], + ["KEY", "key", "2E", "2e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"Present Tense", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter verbs for Preterite Tense", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "3A", "3a"], + ["KEY", "key", "3B", "3b"], + ["KEY", "key", "3C", "3c"], + ["KEY", "key", "3D", "3d"], + ["KEY", "key", "3E", "3e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"Preterite Tense", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter verbs for Imperfect Tense", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "4A", "4a"], + ["KEY", "key", "4B", "4b"], + ["KEY", "key", "4C", "4c"], + ["KEY", "key", "4D", "4d"], + ["KEY", "key", "4E", "4e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"Imperfect Tense", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); }); - - it("Should correctly filter verbs for multiple filters", function() { - // Initialize expected - let expected = [ - ["KEY", "key", "2A", "2a"], - ["KEY", "key", "2B", "2b"], - ["KEY", "key", "2C", "2c"], - ["KEY", "key", "2D", "2d"], - ["KEY", "key", "2E", "2e"], - ["KEY", "key", "3A", "3a"], - ["KEY", "key", "3B", "3b"], - ["KEY", "key", "3C", "3c"], - ["KEY", "key", "3D", "3d"], - ["KEY", "key", "3E", "3e"], - ["KEY", "key", "4A", "4a"], - ["KEY", "key", "4B", "4b"], - ["KEY", "key", "4C", "4c"], - ["KEY", "key", "4D", "4d"], - ["KEY", "key", "4E", "4e"], - - ["KEY", "key", "2A", "2a"], - ["KEY", "key", "2B", "2b"], - ["KEY", "key", "2C", "2c"], - ["KEY", "key", "2D", "2d"], - ["KEY", "key", "2E", "2e"], - - ["KEY", "key", "4A", "4a"], - ["KEY", "key", "4B", "4b"], - ["KEY", "key", "4C", "4c"], - ["KEY", "key", "4D", "4d"], - ["KEY", "key", "4E", "4e"], - ]; - // Filter verbs - let actual = ApplyVerbFilter(verbs, [{"tense":"all", "type":"Nonregular"}, {"tense":"Present Tense", "type":"all"}, {"tense":"all", "type":"Stem Changing"}]); + describe("Regularity filters", function() { + it("Should correctly filter regular verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ]; - // Assert filtered verbs are correct - expect(actual.length).to.equal(expected.length); - for (let i = 0; i < expected.length; i++) { - expect(actual[i].length).to.equal(4); - for (let j = 0; j < expected[i].length; j++) { - expect(actual[i][j]).to.equal(expected[i][j]); - } - } + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"Regular", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter reflexive verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "4A", "4a"], + ["KEY", "key", "4B", "4b"], + ["KEY", "key", "4C", "4c"], + ["KEY", "key", "4D", "4d"], + ["KEY", "key", "4E", "4e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"Reflexive", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter stem changing verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "4A", "4a"], + ["KEY", "key", "4B", "4b"], + ["KEY", "key", "4C", "4c"], + ["KEY", "key", "4D", "4d"], + ["KEY", "key", "4E", "4e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"Stem Changing", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter orthographic verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "3A", "3a"], + ["KEY", "key", "3B", "3b"], + ["KEY", "key", "3C", "3c"], + ["KEY", "key", "3D", "3d"], + ["KEY", "key", "3E", "3e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"Orthographic", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter irregular verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "2A", "2a"], + ["KEY", "key", "2B", "2b"], + ["KEY", "key", "2C", "2c"], + ["KEY", "key", "2D", "2d"], + ["KEY", "key", "2E", "2e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"irregular", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter nonregular verbs", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "2A", "2a"], + ["KEY", "key", "2B", "2b"], + ["KEY", "key", "2C", "2c"], + ["KEY", "key", "2D", "2d"], + ["KEY", "key", "2E", "2e"], + ["KEY", "key", "3A", "3a"], + ["KEY", "key", "3B", "3b"], + ["KEY", "key", "3C", "3c"], + ["KEY", "key", "3D", "3d"], + ["KEY", "key", "3E", "3e"], + ["KEY", "key", "4A", "4a"], + ["KEY", "key", "4B", "4b"], + ["KEY", "key", "4C", "4c"], + ["KEY", "key", "4D", "4d"], + ["KEY", "key", "4E", "4e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"all subjects", type:"Nonregular", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + }); + + describe("Subject filters", function() { + it("Should correctly filter yo subjects", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ["KEY", "key", "2A", "2a"], + ["KEY", "key", "3A", "3a"], + ["KEY", "key", "4A", "4a"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"yo", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter tú subjects", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ["KEY", "key", "2B", "2b"], + ["KEY", "key", "3B", "3b"], + ["KEY", "key", "4B", "4b"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"tú", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter él subjects", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ["KEY", "key", "2C", "2c"], + ["KEY", "key", "3C", "3c"], + ["KEY", "key", "4C", "4c"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"él", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter nosotros subjects", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ["KEY", "key", "2D", "2d"], + ["KEY", "key", "3D", "3d"], + ["KEY", "key", "4D", "4d"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"nosotros", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter ellos subjects", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ["KEY", "key", "2E", "2e"], + ["KEY", "key", "3E", "3e"], + ["KEY", "key", "4E", "4e"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"all tenses", subject:"ellos", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + }); + + describe("Direction filters", function() { + it("Should correctly filter English to Conjugations", function() { + // Initialize expected + let expected = [ + ["KEY", "key", "1A", "1a"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"present participles", subject:"all subjects", type:"all types", direction:"Eng. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter Spanish to Conjugations", function() { + // Initialize expected + let expected = [ + ["SPANISH INF", "spanish inf", "1A", "1a"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"present participles", subject:"all subjects", type:"all types", direction:"Esp. => Conj."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter Conjugations to English", function() { + // Initialize expected + let expected = [ + ["1A", "1a", "KEY", "key"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"present participles", subject:"all subjects", type:"all types", direction:"Conj. => Eng."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); + + it("Should correctly filter Conjugations to Spanish", function() { + // Initialize expected + let expected = [ + ["1A", "1a", "SPANISH INF", "spanish inf"], + ]; + + // Filter verbs + let actual = ApplyVerbFilter(verbs, [{tense:"present participles", subject:"all subjects", type:"all types", direction:"Conj. => Esp."}]); + + // Assert filtered verbs are correct + expect(actual).to.have.deep.members(expected); + }); }); });