Skip to content

Words-Test #3

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Empty file added ExerciseOne/.gitignore
Empty file.
2 changes: 1 addition & 1 deletion ExerciseOne/test-words-utility.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Unit Tests for - the words utility</title>
<link rel="stylesheet" type="text/css" href="../qunit/qunit.css">
<script src="../qunit/qunit.js"></script>
<script src="../qunit/qunit-reporter-junit.js"></script>

<script src="words-utility.js"></script>
<script src="words-utility-tests.js"></script>
</head>
Expand Down
19 changes: 19 additions & 0 deletions ExerciseOne/test-words-utility.html~
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Unit Tests for - the words utility</title>
<link rel="stylesheet" type="text/css" href="../qunit/qunit.css">
<script src="../qunit/qunit.js"></script>
<script src="../qunit/qunit-reporter-junit.js"></script>
<script src="words-utility.js"></script>
<script src="words-utility-tests.js"></script>
</head>
<body>
<div id="qunit">

</div>
<div id="qunit-fixture">

</div>
</body>
</html>
100 changes: 91 additions & 9 deletions ExerciseOne/words-utility-tests.js
Original file line number Diff line number Diff line change
@@ -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);
};
Expand Down
48 changes: 48 additions & 0 deletions ExerciseOne/words-utility-tests.js~
Original file line number Diff line number Diff line change
@@ -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

148 changes: 147 additions & 1 deletion ExerciseOne/words-utility.js
Original file line number Diff line number Diff line change
@@ -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.length;i++){

var Lang = wordCollection[i].toLowerCase();
if(!SameLength[Lang.length]){
SameLength[Lang.length]=[];
}
SameLength[Lang.length].push(Lang);

}


return SameLength;
}





this.shortestWord= function(){
var wordCollection=words.split(" ");

var shortWord = wordCollection[wordCollection.length-1];

for(i =0; i < wordCollection.length; i++){
if(shortWord.length > wordCollection[i].length){
shortWord = wordCollection[i];

}


}

return shortWord;

}







this.mostWordsEndWith= function(){

var wordCollection=words.split(" ");
var EndWith={};


for(i=0;i<wordCollection.length;i++){
var letter=wordCollection[i].charAt(wordCollection[i].length-1).toLowerCase();
if(letter==="."||letter==","){
letter=wordCollection[i].charAt(wordCollection[i].length-2).toLowerCase();
}
if(!EndWith[letter]){
EndWith[letter]=[];

}
EndWith[letter].push(letter);


}


return letter
}

this.mostWordsStartWith= function(){


var wordCollection=words.split(" ");

var StartWith={};


for(i=0;i<wordCollection.length;i++){

var letter=wordCollection[i][0].toLowerCase();
if(!StartWith[letter]){
StartWith[letter]=[];
}
StartWith[letter].push(wordCollection[i]);

}



return letter;

}



}
Loading