def test_remove(self): HW4.download_if_needed('http://s3.amazonaws.com/pronto-data/open_data_year_one.zip', 'open_data_year_one.zip') #before remove_data, data are present self.assertTrue(os.path.exists('open_data_year_one.zip')) HW4.remove_data() #after remove_data, data are not present self.assertFalse(os.path.exists('open_data_year_one.zip'))
def test_download(self): HW4.get_pronto_data() if os.path.exists('daily_totals.png'): os.remove('daily_totals.png') #before plot no png flile self.assertFalse(os.path.exists('daily_totals.png')) HW4.plot_daily_totals() #after plot, png file is present self.assertTrue(os.path.exists('daily_totals.png'))
def test_download(self): #test when data are not present HW4.remove_data() #test when the url is not valid with self.assertRaises(urllib3.exceptions.MaxRetryError): HW4.download_if_needed('http://s3.23amazonaws.com/pronto-data/open_data_year_one.zip', 'open_data_year_one.zip') #test when url is valid HW4.download_if_needed('http://s3.amazonaws.com/pronto-data/open_data_year_one.zip', 'open_data_year_one.zip') self.assertTrue(os.path.exists('open_data_year_one.zip')) #test when data are present out = HW4.download_if_needed('http://s3.amazonaws.com/pronto-data/open_data_year_one.zip', 'open_data_year_one.zip') assert out == 'open_data_year_one.zip already exists'
def test11(self): #with self.assertRaises(TypeError): self.assertEqual(HW4.full_name_generator(['h','i'],'burger'),'hiburger')
def test12(self): self.assertEqual(HW4.full_name_generator('cheese','burger'),'cheeseburger')
def test10(self): #with self.assertRaises(TypeError): self.assertEqual(HW4.full_name_generator('2',3),'23')
def test1(self): #with self.assertRaises(AssertionError): self.assertEqual(HW4.find_cube_volume(-2),8)
def test8(self): self.assertEqual(HW4.list_average([4,4,4,4]),4)
def test9(self): #with self.assertRaises(AssertionError): self.assertEqual(HW4.full_name_generator(1,2),'12')
def test_two(self): self.assertEqual(HW4.cube('h'), "Type Error") self.assertEqual(HW4.cube('five'), "Type Error") self.assertEqual(HW4.cube([5, -5]), "Type Error")
def test_one(self): self.assertEqual(HW4.avg([]), "Zero Division") self.assertEqual(HW4.avg([-5]), -5) self.assertEqual(HW4.avg([5]), 5)
def test4(self): self.assertEqual(HW4.find_cube_volume(2),8)
def test5(self): #with self.assertRaises(ZeroDivisionError): self.assertEqual(HW4.list_average([]),2)
def test3(self): #with self.assertRaises(TypeError): self.assertEqual(HW4.find_cube_volume("2"),8)
def test_three(self): self.assertEqual(HW4.avg([1, 3]), 2) self.assertEqual(HW4.avg([3, 5, 7]), 5) self.assertEqual(HW4.avg([-3, -7, -5]), -5)
def test_two(self): self.assertEqual(HW4.avg('five'), "Type Error") self.assertEqual(HW4.avg(0), "Type Error") self.assertEqual(HW4.avg('0'), "Type Error")
def test2(self): #with self.assertRaises(AssertionError): self.assertEqual(HW4.find_cube_volume(complex(2,3)),8)
def test_one(self): self.assertEqual(HW4.cube(5), 125) self.assertEqual(HW4.cube(3), 27) self.assertEqual(HW4.cube(0), 0)
def test6(self): #with self.assertRaises(TypeError): self.assertEqual(HW4.list_average(),0)
def test_three(self): self.assertEqual(HW4.cube(-5), "Negative Edge Length") self.assertEqual(HW4.cube(complex(3, 5)), "Complex Edge Length") self.assertEqual(HW4.cube(complex(-3, -5)), "Complex Edge Length")
def test7(self): #with self.assertRaises(TypeError): self.assertEqual(HW4.list_average(['4',4,4,4]),2)
import HW4 as Cls PROB = 0.4 TIME_STEPS = 20 Realization_times = 1000 myGame = Cls.Games(realization_times=Realization_times, prob=PROB) # simulate myGame.simulate(TIME_STEPS) # print print(myGame.get_ave_exp_cost()) print(myGame.get_total_time())