Skip to content
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

exercise 4 #71

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
39 changes: 36 additions & 3 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,41 @@ function Map(posts) {
this._posts = posts;
}

Map.prototype.find_a_person = function(name) {
return [];
};
Map.prototype.find_a_person = function(name)
{
var posts = [];
for(var i =0; i<this._posts.length; i++)
if(this._posts[i].search(name) >= 0)
posts.push(this._posts[i]);
return posts;
};

Map.prototype.find_a_location = function(name) {
for(var i =0; i<this._posts.length; i++)
if(this._posts[i].search(name) >= 0)
return true;
return false;
};

Map.prototype.find_inconsistencies = function(name)
{
if(this.find_a_person(name).length > 1)
return false;
else
return true;
};

Map.prototype.is_name_show_by_post = function(name) {
for(var i =0; i<this._posts.length; i++)
if(this._posts[i].search(name) < 0)
return true;
return false;
}

Map.prototype.find_any_collaboration = function(name){
return true;
};



module.exports = Map;
29 changes: 28 additions & 1 deletion tests/find-a-person.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

var chai = require('chai');
var expect = chai.expect; // we are using the "expect" style of Chai
var Map = require('./../src/map');
Expand All @@ -8,4 +9,30 @@ describe('Find a person', function() {
var posts = map.find_a_person("Or A.")
expect(posts).to.be.eql(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley"]);
});
});

it('Given a name, check if the map includes a location information for it (a place or geo. location)', function() {
var map = new Map(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley", "Random post"]);
var location_exsit = map.find_a_location("Or A.");
expect(location_exsit).to.be.eql(true);
});

it('Check if there are map inconsistencies, e.g., the same name with different locations',function()
{
var map = new Map(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley", "Random post"]);
var inc = map.find_inconsistencies("or A.")
expect(inc).to.be.eql(true);
});

it('Given a person name, check if he appears in a post', function() {
var map = new Map(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley", "Random post"]);
var isAppear = map.is_name_show_by_post("Or A.");
expect(isAppear).to.be.eql(true);
});

it('Check if there are any Collaboration',function(){
var map = new Map(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley", "Random post"]);
var col = map.find_any_collaboration("or A.")
expect(col).to.be.eql(true);
});

});