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

hw- test TDD #11

Open
wants to merge 3 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
41 changes: 41 additions & 0 deletions Crowdmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
__author__ = 'tamar'
class Crowdmap(object):
def __init__(self, init_list):
self.list = init_list
self.location_service = LocationService()

def get_all_posts_for(self, name):
return [post for post in self.list if post.find(name) != -1]

def is_location_for_name(self, name):
name_posts = self.get_all_posts_for(name)
for post in name_posts:
if self.location_service.find(post): # if location_service.find(post):
return True
return False

def getlocation(self,post):
return post.find("Bangkok")

def is_diff_location_for_name(self,name):
name_post=self.get_all_posts_for(name)
locations=self.location_service.getallplace(name)
return (len(locations)!=1)

class LocationService:
def find(self, text):
return (text.find("Bangkok") != -1 or text.find("Langtang") != -1)

def getallplace(self, name):
list=[]
for post in name:
if self.find(post):
list.insert(len(list), self.getLocations(post))
return list

def getLocations(self, text):
if text.find("Bangkok") != -1:
return "Bangkok"
if text.find("Langtang") != -1:
return "Langtang"

27 changes: 27 additions & 0 deletions FindProjTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from Crowdmap import Crowdmap

class FindProjTests(unittest.TestCase):
def setUp(self):
self.crowdmap= Crowdmap(["I met Or A. at Chabad house Bangkok","We found Or A. R.I.P at Langtang valley","Missing Cowboy"])

def test_get_all_posts_for_name(self):
posts= self.crowdmap.get_all_posts_for("Or A.")
self.assertEquals(["I met Or A. at Chabad house Bangkok","We found Or A. R.I.P at Langtang valley"],posts)


def test_get_all_posts_for_missing_name(self):
posts = self.crowdmap.get_all_posts_for("Joe")
self.assertEquals([],posts)

def test_check_if_location_in_post(self):
location_exist=self.crowdmap.is_location_for_name("Or")
self.assertTrue(location_exist)

def test_check_if_diff_location_in_post(self):
location_exist=self.crowdmap.is_diff_location_for_name("Or")
self.assertTrue(location_exist)

if __name__ == '__main__':
unittest.main()