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..c41367e 100644
--- a/ExerciseOne/words-utility-tests.js
+++ b/ExerciseOne/words-utility-tests.js
@@ -1,40 +1,122 @@
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.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("ola yeah yoyoyo yoda");
+ var wordsUtility = new WordsUtility(theWords);
- assert.equal(0, wordsUtility.wordsWithTheSameLength().length);
+ assert.equal(undefined, 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(), "s");
+});
+
+QUnit.test( "most words start with", function( assert ) {
+ var wordsUtility = new WordsUtility(theWords);
+ assert.equal(wordsUtility.mostWordsStartWith(), "t");
+});
+
+
+
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..6bcccde 100644
--- a/ExerciseOne/words-utility.js
+++ b/ExerciseOne/words-utility.js
@@ -1,7 +1,153 @@
+//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 wordCollection=words.split(" ");
+ var SameLength={};
+
+ for(i=0;i wordCollection[i].length){
+ shortWord = wordCollection[i];
+
+ }
+
+
+ }
+
+ return shortWord;
+
+ }
+
+
+
+
+
+
+
+ this.mostWordsEndWith= function(){
+
+ var wordCollection=words.split(" ");
+ var EndWith={};
+
+
+ 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
+
+
+
+
+
+
+
+