Esempio n. 1
0
	def testAddingAdjacentStreetArea(self):
		"""test adding an adjacent street area for a street area"""
		s = area()
		s2 = area()
		s.addArea(s2)
		self.assertTrue(s.adjAreas.has_key(s2.name))
		self.assertEqual(s2, s.adjAreas[s2.name])
Esempio n. 2
0
	def testDistanceToArea(self):
		"""test measuring the distance to an area"""
		s1 = area('street1')
		s2 = area('street2')
		s3 = area('stret3')
		s4 = area('street4')

		s1.addArea(s2)
		s2.addArea(s1)
		s2.addArea(s3)
		s3.addArea(s2)
		s3.addArea(s4)
		s4.addArea(s3)

		d = s1.distanceTo('street4')
		self.assertEqual(d, 3)
Esempio n. 3
0
	def testAddingAdjacentLocation(self):
		"""test adding an adjacent location for a street area"""
		s = area()
		l = location('Joukkila')
		s.addLocation(l)
		self.assertTrue(s.adjLocs.has_key(l.name))
		self.assertEqual(l, s.adjLocs[l.name])
Esempio n. 4
0
	def testDistanceToadjacentArea(self):
		"""test measuring the distance to adjacent area"""
		l = location('location')
		s = area('area')
		l.adjArea = s
		s.addLocation(l)
		d = l.distanceTo('area')
		self.assertEqual(1, d)
Esempio n. 5
0
	def testAddingStreet(self):
		"""test adding a street location on a board"""
		b = board()
		s = area()
		s.name = 'Street'
		b.addStreet(s)
		self.assertTrue(s.name in b.streets)
		self.assertEqual(s, b.streets[s.name])
Esempio n. 6
0
	def testDistanceToLocation(self):
		"""test measuring the distance to a location"""
		s1 = area('street1')
		s2 = area('street2')

		l1 = location('l1')
		l2 = location('l2')
		l3 = location('l3')

		s1.addLocation(l1)
		s1.addLocation(l2)
		s1.addArea(s2)
		s2.addLocation(l3)
		s2.addArea(s1)

		d = s1.distanceTo('l3')
		self.assertEqual(d, 2)
Esempio n. 7
0
	def testDistanceToAdjacentLocation(self):
		"""test measuring the distance to an adjacent location"""
		s = area('area')
		l = location('location')
		s.addLocation(l)
		l.adjArea = s
		d = s.distanceTo('location')
		self.assertEqual(d, 1)
Esempio n. 8
0
	def testReachableAreas(self):
		"""test finding reachable street areas"""
		s1 = area('street1')
		s2 = area('street2')
		s3 = area('stret3')
		s4 = area('street4')

		s1.addArea(s2)
		s2.addArea(s1)
		s2.addArea(s3)
		s3.addArea(s2)
		s3.addArea(s4)
		s4.addArea(s3)

		r = s1.reachables(2)
		self.assertTrue(len(r) == 3)
		self.assertTrue(s2.name in r)
		self.assertTrue(s3.name in r)
		self.assertFalse(s4.name in r)
Esempio n. 9
0
	def testReachableArea(self):
		"""test finding the area reachable from a location"""
		l = location('location')
		s = area('street')
		l.adjArea = s
		s.addLocation(l)
		
		r = l.reachables(1)
		self.assertTrue(s.name in r)
		self.assertTrue(l.name in r)
		self.assertEqual(len(r), 2)
Esempio n. 10
0
	def testReachableLocations(self):
		"""test finding reachable locations"""
		s1 = area('street1')
		s2 = area('street2')

		l1 = location('l1')
		l2 = location('l2')
		l3 = location('l3')

		s1.addLocation(l1)
		s1.addLocation(l2)
		s1.addArea(s2)
		s2.addLocation(l3)
		s2.addArea(s1)

		r = s1.reachables(1)
		self.assertEqual(len(r), 4)
		self.assertTrue(l1.name in r)
		self.assertTrue(l2.name in r)
		self.assertTrue(s2.name in r)
		self.assertFalse(l3.name in r)
Esempio n. 11
0
def turkuboard():
	"""returns the board of Turku"""

	"""Kartta:

	Student Village	
	  |
	  |
	Riverside -- University Campus
	  |
	  |
	Harbor
	"""

	campus = area('University Campus')
	hill = location('University Hill')
	hill.adjArea = campus
	park = location('Science Park')
	park.adjArea = campus
	sirkkala = location('Sirkkala')
	sirkkala.adjArea = campus
	campus.addLocation(hill)
	campus.addLocation(park)
	campus.addLocation(sirkkala)

	harbor = area('Harbor')
	castle = location('Turku Castle')
	castle.adjArea = harbor
	docks = location('Cargo Docks')
	docks.adjArea = harbor
	terminals = location('Cruiser Terminals')
	terminals.adjArea = harbor
	harbor.addLocation(castle)
	harbor.addLocation(docks)
	harbor.addLocation(terminals)

	river = area('Riverside')
	market = location('Old Marketsquare')
	market.adjArea = river
	church = location('Doom Church')
	church.adjArea = river
	fori = location('Föri the Ferry')
	fori.adjArea = river
	river.addLocation(market)
	river.addLocation(church)
	river.addLocation(fori)
	
	joukkila = area('Student Village')
	caribia = location('Caribia Hotel')
	caribia.adjArea = joukkila
	graveyard = location('Graveyard')
	graveyard.adjArea = joukkila
	pub = location('Pub Three Beers')
	pub.adjArea = joukkila 
	joukkila.addLocation(caribia)
	joukkila.addLocation(graveyard)
	joukkila.addLocation(pub)

	joukkila.addArea(river)
	river.addArea(joukkila)
	river.addArea(campus)
	river.addArea(harbor)
	campus.addArea(river)
	harbor.addArea(river)

	b = board()

	b.streets = {campus.name:campus, harbor.name:harbor, river.name:river, joukkila.name:joukkila}

	b.locs = {hill.name:hill, park.name:park, sirkkala.name:park, \
	castle.name:castle, docks.name:docks, terminals.name:terminals, \
	market.name:market, church.name:church, fori.name:fori, \
	caribia.name:caribia, graveyard.name:graveyard, pub.name:pub}
	
	return b
Esempio n. 12
0
	def testDistanceToSelf(self):
		"""test measuring the distance to area itself"""
		s = area('area')
		d = s.distanceTo('area')
		self.assertEqual(d, 0)
Esempio n. 13
0
	def testDistanceToNowhere(self):
		"""test measuring the distance to a place that does not exist"""
		s = area('area')
		self.assertRaises(NoSuchDestinationFromAreaError, s.distanceTo, 'Nowhere')