import unittest
import p2

class P2Tester(unittest.TestCase):
	def assertNoOrder(self, first, second):
		self.assertEqual(set(first), set(second))
	def test_sample(self):
		songs = [
			('Man In A Box', 'Alice In Chains', ('famous', 'power')),
			('Frogs', 'Alice In Chains', ('sad',)),
			('Right Turn', 'Alice In Chains', ('cornell',)),
			('Hunger Strike', 'Temple of the Dog', ('vedder',)),
			('Reach Down', 'Temple of the Dog', ()),
			('Long Gone Day', 'Mad Season', ('saxophone', 'lanegan')),
			('November Hotel', 'Mad Season', ('power',)),
			('Nearly Lost You', 'Screaming Trees', ()),
			('Indifference', 'Pearl Jam', ('sad',)),
			('Thursday', 'Morphine', ('power',)),
			('Outshined', 'Soundgarden', ()),
			('Have a Cigar', 'Pink Floyd', ('saxophone',)),
			('Time', 'Pink Floyd', ())
		]
		bands = [
			('Alice In Chains', ('staley', 'grunge')),
			('Temple of the Dog', ('grunge', 'cornell')),
			('Pearl Jam', ('vedder', 'grunge')),
			('Screaming Trees', ('lanegan', 'grunge')),
			('Morphine', ('low rock', 'saxophone')),
			('Pink Floyd', ('psychadelic',)),
			('Soundgarden', ('grunge', 'cornell')),
			('Mad Season', ('grunge', 'staley'))
		]
		tags_by_band, songs_by_tags, songs_by_band = p2.build(songs, bands)
		self.assertNoOrder('staley grunge famous power sad cornell'.split(), tags_by_band('Alice In Chains'))
		self.assertNoOrder([('Man In A Box', 'Alice In Chains'), ('November Hotel', 'Mad Season')], songs_by_tags('power', 'grunge'))
		self.assertNoOrder(['Hunger Strike', 'Reach Down'], songs_by_band('Temple of the Dog'))

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