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

TDD-Kata by hanni gabai #25

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

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):
posts = [post for post in self.list if post.find(name) != -1 and post.find("at") != -1]
return len(posts) != 0

def if_there_are_map_inconsistencies(self, name):
posts = [post for post in self.list if post.find(name) != -1 and post.find("at") != -1]
x=posts[0].index("at")
posts1 = [post for post in self.list if post.find(name) != -1 and post.find(posts[0][x:x+4]) != -1]
print '\n'+posts[0][x:x+4]
return len(posts) != len(posts1)

def if_there_are_map_inconsistencies_all_name_place(self, name):
posts = [post for post in self.list if post.find(name) != -1 and post.find("at") != -1]
words=posts[0].split()
place=words.index("at")+1
print '\n'+str(place)
print '\n'+words[place]
posts1 = [post for post in self.list if post.find(name) != -1 and post.find(words[place]) != -1]
return len(posts) != len(posts1)

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

class FindAPersonTests(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_getAllPostsForName(self):
posts = self.crowdmap.get_all_posts_for("Or")
self.assertEquals(["I met Or A. at Chabad house Bangkok", "We found Or A. R.I.P at Langtang valley"], posts)

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

def test_missinfLocationInformationReturnsFalse(self):
location_exist = self.crowdmap.is_location_for_name("hanni")
self.assertFalse(location_exist)

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

def test_if_there_are_map_inconsistencies(self):
location_exist = self.crowdmap.if_there_are_map_inconsistencies("Or A.")
self.assertTrue(location_exist)

def test_if_there_are_map_consistencies(self):
crowdmap_with_consistencies = Crowdmap(["I met Or A. at AAB house Bangkok",
"We found Or A. R.I.P at AAA valley",
"Missing Cowboy"])
location_exist=crowdmap_with_consistencies.if_there_are_map_inconsistencies("Or A.")
self.assertFalse(location_exist)

def test_if_there_are_map_consistencies_all_name_place(self):
crowdmap_with_consistencies_all_name_place = Crowdmap(["I met Or A. at BAB house Bangkok",
"We found Or A. R.I.P at AAA valley",
"Missing Cowboy"])
location_exist = crowdmap_with_consistencies_all_name_place.if_there_are_map_inconsistencies_all_name_place("Or A.")
self.assertTrue(location_exist)

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