From 4145047084b2ae1d99eb340b13763f3dd4cf3938 Mon Sep 17 00:00:00 2001 From: Mawande06 Date: Tue, 21 Oct 2014 16:26:54 +0200 Subject: [PATCH 1/2] Words-Test --- ExerciseOne/gitignore | 0 ExerciseOne/test-words-utility.html | 2 +- ExerciseOne/test-words-utility.html~ | 19 +++++ ExerciseOne/words-utility-tests.js | 35 ++++++-- ExerciseOne/words-utility-tests.js~ | 48 +++++++++++ ExerciseOne/words-utility.js | 118 ++++++++++++++++++++++++++- ExerciseOne/words-utility.js~ | 59 ++++++++++++++ 7 files changed, 270 insertions(+), 11 deletions(-) create mode 100644 ExerciseOne/gitignore create mode 100644 ExerciseOne/test-words-utility.html~ create mode 100644 ExerciseOne/words-utility-tests.js~ create mode 100644 ExerciseOne/words-utility.js~ diff --git a/ExerciseOne/gitignore b/ExerciseOne/gitignore new file mode 100644 index 0000000..e69de29 diff --git a/ExerciseOne/test-words-utility.html b/ExerciseOne/test-words-utility.html index cbe60b4..d499f5e 100644 --- a/ExerciseOne/test-words-utility.html +++ b/ExerciseOne/test-words-utility.html @@ -4,7 +4,7 @@ Unit Tests for - the words utility - + diff --git a/ExerciseOne/test-words-utility.html~ b/ExerciseOne/test-words-utility.html~ new file mode 100644 index 0000000..cbe60b4 --- /dev/null +++ b/ExerciseOne/test-words-utility.html~ @@ -0,0 +1,19 @@ + + + + Unit Tests for - the words utility + + + + + + + +
+ +
+
+ +
+ + diff --git a/ExerciseOne/words-utility-tests.js b/ExerciseOne/words-utility-tests.js index 1f0c35a..99fd922 100644 --- a/ExerciseOne/words-utility-tests.js +++ b/ExerciseOne/words-utility-tests.js @@ -1,40 +1,57 @@ var theWords = "A Unit Test is a piece of code that is using your code, exercising some scenarios that it expects to work in a certain way. Unit tests are isolated from external dependencies unlike integration tests. We will focus on Unit Tests."; + QUnit.test( "test if words are counted correctly", function( assert ) { var wordsUtility = new WordsUtility(theWords); assert.equal(wordsUtility.countWords(), 41); }); QUnit.test( "find the longest word", function( assert ) { - var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda"); - assert.equal(wordsUtility.longestWord(), "yoyoyo"); + var wordsUtility = new WordsUtility(theWords); + + assert.equal(wordsUtility.longestWord(), "dependencies"); }); QUnit.test( "the average word length of words supplied", function( assert ) { - var wordsUtility = new WordsUtility("ola yeah yoyoyo"); - assert.equal(wordsUtility.averageWordLength(), "ola"); + var wordsUtility = new WordsUtility(theWords); + + assert.equal(wordsUtility.averageWordLength(), " 5.585365853658536"); }); QUnit.test( "find words with the same length", function( assert ) { - var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda"); + var wordsUtility = new WordsUtility(theWords); var words = wordsUtility.wordsWithTheSameLength(); + assert.equal(wordsUtility.wordsWithTheSameLength(), " ") }); QUnit.test( "no words with the same length return nothing", function( assert ) { - var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda"); + var wordsUtility = new WordsUtility(theWords); - assert.equal(0, wordsUtility.wordsWithTheSameLength().length); + assert.equal(0, wordsUtility.wordsWithTheSameLength().length, 5); }); QUnit.test( "find the shortest word", function( assert ) { - var wordsUtility = new WordsUtility("ola yeah yoyoyo"); - assert.equal(wordsUtility.shortestWord(), "ola"); + var wordsUtility = new WordsUtility(theWords); + assert.equal(wordsUtility.shortestWord(), "A"); }); + +QUnit.test( "most words end with", function( assert ) { + var wordsUtility = new WordsUtility(theWords); + assert.equal(wordsUtility.mostWordsEndWith(), "A"); +}); + +QUnit.test( "most words start with", function( assert ) { + var wordsUtility = new WordsUtility(theWords); + assert.equal(wordsUtility.mostWordsStartWith(), "A"); +}); + + + QUnit.jUnitReport = function(report) { console.log(report.xml); }; diff --git a/ExerciseOne/words-utility-tests.js~ b/ExerciseOne/words-utility-tests.js~ new file mode 100644 index 0000000..0b58b3e --- /dev/null +++ b/ExerciseOne/words-utility-tests.js~ @@ -0,0 +1,48 @@ + +var theWords = "A Unit Test is a piece of code that is using your code, exercising some scenarios that it expects to work in a certain way. Unit tests are isolated from external dependencies unlike integration tests. We will focus on Unit Tests."; + + +QUnit.test( "test if words are counted correctly", function( assert ) { + var wordsUtility = new WordsUtility(theWords); + assert.equal(wordsUtility.countWords(), 41); +}); + +QUnit.test( "find the longest word", function( assert ) { + var wordsUtility = new WordsUtility(theWords); + + assert.equal(wordsUtility.longestWord(), "dependencies"); +}); + +QUnit.test( "the average word length of words supplied", function( assert ) { + var wordsUtility = new WordsUtility(theWords); + + assert.equal(wordsUtility.averageWordLength(), "1"); +}); + +QUnit.test( "find words with the same length", function( assert ) { + + var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda"); + var words = wordsUtility.wordsWithTheSameLength(); +}); + + +QUnit.test( "no words with the same length return nothing", function( assert ) { + var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda"); + + assert.equal(0, wordsUtility.wordsWithTheSameLength().length); + +}); + +QUnit.test( "find the shortest word", function( assert ) { + var wordsUtility = new WordsUtility("ola yeah yoyoyo"); + assert.equal(wordsUtility.shortestWord(), "ola"); +}); + +QUnit.jUnitReport = function(report) { + console.log(report.xml); +}; + +//create a test for What letter does the most words start with + +//create a test for What letter does the most words end with + diff --git a/ExerciseOne/words-utility.js b/ExerciseOne/words-utility.js index 661ba0f..d3aba34 100644 --- a/ExerciseOne/words-utility.js +++ b/ExerciseOne/words-utility.js @@ -1,7 +1,123 @@ +//var theWords = "A Unit Test is a piece of code that is using your code, exercising some scenarios that it expects to work in a certain way. Unit tests are isolated from external dependencies unlike integration tests. We will focus on Unit Tests."; -WordsUtility = function(words){ + + + + WordsUtility = function(words){ + + this.countWords = function(){ + + var numberOfWords= words.split(" ").length; return words.split(" ").length; } + + this.longestWord = function(){ + // describe step one + + // describe step two + + // describe step three + + // return the longest word + var longWord = ""; + var wordCollection=words.split(" "); + for(i =0; i < wordCollection.length; i++){ + if(longWord.length < wordCollection[i].length){ + longWord = wordCollection[i]; + } + } + + return longWord + + //return "dependencies"; + + } + + + + this.averageWordLength= function(){ + var numberOfWords= words.split(" ").length; + var wordCollection=words.split(" "); + + //go to each word and find it's length + // add this length to a variable initialized out side of the loop - totalLength for example + + //once done divide totalLength with numberOfWords + var totalLength=wordCollection.join("+").length; + for(i=0;i<1;i++){ + + return totalLength/ numberOfWords + } + + + } + + this.wordsWithTheSameLength= function(){ + var sameLength = 0; + var sameCollection=[] + var wordCollection=words.split(" "); + for(i=0;i wordCollection[i].length){ + shortWord = wordCollection[i]; + + } + + + } + + return shortWord; + + } + + + + + + + + this.mostWordsEndWith= function(){ + var EndWith=0; + var wordCollection=words.split(" "); + for(i=0;i Date: Wed, 29 Oct 2014 14:18:37 +0200 Subject: [PATCH 2/2] modified --- ExerciseOne/{gitignore => .gitignore} | 0 ExerciseOne/words-utility-tests.js | 73 +++++++++++++++++++++-- ExerciseOne/words-utility.js | 74 +++++++++++++++++------- ExerciseTwo/numbers-utility-test.js | 47 +++++++++++++++ ExerciseTwo/numbers-utility-test.js~ | 43 ++++++++++++++ ExerciseTwo/numbers-utility.js | 83 +++++++++++++++++++++++++++ ExerciseTwo/numbers-utility.js~ | 78 +++++++++++++++++++++++++ ExerciseTwo/test-numbers-utility.html | 19 ++++++ 8 files changed, 391 insertions(+), 26 deletions(-) rename ExerciseOne/{gitignore => .gitignore} (100%) create mode 100644 ExerciseTwo/numbers-utility-test.js create mode 100644 ExerciseTwo/numbers-utility-test.js~ create mode 100644 ExerciseTwo/numbers-utility.js create mode 100644 ExerciseTwo/numbers-utility.js~ create mode 100644 ExerciseTwo/test-numbers-utility.html diff --git a/ExerciseOne/gitignore b/ExerciseOne/.gitignore similarity index 100% rename from ExerciseOne/gitignore rename to ExerciseOne/.gitignore diff --git a/ExerciseOne/words-utility-tests.js b/ExerciseOne/words-utility-tests.js index 99fd922..c41367e 100644 --- a/ExerciseOne/words-utility-tests.js +++ b/ExerciseOne/words-utility-tests.js @@ -23,14 +23,79 @@ QUnit.test( "find words with the same length", function( assert ) { var wordsUtility = new WordsUtility(theWords); var words = wordsUtility.wordsWithTheSameLength(); - assert.equal(wordsUtility.wordsWithTheSameLength(), " ") + assert.deepEqual(wordsUtility.wordsWithTheSameLength(), { "1": [ + "a", + "a", + "a" + ], + "10": [ + "exercising" + ], + "11": [ + "integration" + ], + "12": [ + "dependencies" + ], + "2": [ + "is", + "of", + "is", + "it", + "to", + "in", + "we", + "on" + ], + "3": [ + "are" + ], + "4": [ + "unit", + "test", + "code", + "that", + "your", + "some", + "that", + "work", + "way.", + "unit", + "from", + "will", + "unit" + ], + "5": [ + "piece", + "using", + "code,", + "tests", + "focus" + ], + "6": [ + "unlike", + "tests.", + "tests." + ], + "7": [ + "expects", + "certain" + ], + "8": [ + "isolated", + "external" + ], + "9": [ + "scenarios" + ] +}) }); QUnit.test( "no words with the same length return nothing", function( assert ) { var wordsUtility = new WordsUtility(theWords); - assert.equal(0, wordsUtility.wordsWithTheSameLength().length, 5); + assert.equal(undefined, wordsUtility.wordsWithTheSameLength().length, 5); }); @@ -42,12 +107,12 @@ QUnit.test( "find the shortest word", function( assert ) { QUnit.test( "most words end with", function( assert ) { var wordsUtility = new WordsUtility(theWords); - assert.equal(wordsUtility.mostWordsEndWith(), "A"); + assert.equal(wordsUtility.mostWordsEndWith(), "s"); }); QUnit.test( "most words start with", function( assert ) { var wordsUtility = new WordsUtility(theWords); - assert.equal(wordsUtility.mostWordsStartWith(), "A"); + assert.equal(wordsUtility.mostWordsStartWith(), "t"); }); diff --git a/ExerciseOne/words-utility.js b/ExerciseOne/words-utility.js index d3aba34..6bcccde 100644 --- a/ExerciseOne/words-utility.js +++ b/ExerciseOne/words-utility.js @@ -55,17 +55,21 @@ } this.wordsWithTheSameLength= function(){ - var sameLength = 0; - var sameCollection=[] - var wordCollection=words.split(" "); - for(i=0;i smallNumber){ + smallNumber=myNumbers[i] + } + } + return smallNumber; + +} + + this.evenNumbers= function(){ + var even=0; + for(i=0;i< myNumbers.length;i++){ + if(theNumbers[i] % 2 === 0){ + even=theNumbers[i] + } + } + return even; +} + + this.UnevenNumbers= function(){ + + var uneven=0; + for(i=0;i< myNumbers.length;i++){ + if(myNumbers[i] % 2 !== 0){ + uneven=myNumbers[i] + + } + } +return uneven; + } +} diff --git a/ExerciseTwo/numbers-utility.js~ b/ExerciseTwo/numbers-utility.js~ new file mode 100644 index 0000000..9a72f78 --- /dev/null +++ b/ExerciseTwo/numbers-utility.js~ @@ -0,0 +1,78 @@ + +WordsUtility = function(words){ + + var numberOfWords= words.split("").length; + + this.countWords = function(){ + return words.split(" ").length; + } + + this.longestWord = function(){ + + + + var words = words.split(" ").length; + + var longest = 0; + + var answer = ""; + + for(var i=0; i<=words.length; i++) { + + words[i] = words[i].replace(/[^a-zA-Z]+/g, ""); + + if(words[i].length>longest) { + + longest = words[i].length; + + answer = words[i]; + + + + } + + return answer; + +} + + + + + + + } + + this.averageWordLength= function(){ + + var WordLengthWithoutSpace = theWords.length - (numberOfWords-2); + + return WordLengthWithoutSpace / numberOfWords + + + } + + this.wordsWithTheSameLength= function(){ + + + +} + + this.shortestWord= function(){ + + + + +} + + this.mostWordsEndWith= function(){ + + + +} + + this.mostWordsStartWith= function(){ + + + +} +} diff --git a/ExerciseTwo/test-numbers-utility.html b/ExerciseTwo/test-numbers-utility.html new file mode 100644 index 0000000..e50ddec --- /dev/null +++ b/ExerciseTwo/test-numbers-utility.html @@ -0,0 +1,19 @@ + + + + Unit Tests for - the numbers utility + + + + + + + +
+ +
+
+ +
+ +