def test_df_ctr_all(self): ''' test whether the df_ctr_all function in AnalysisAndLinePlot module returns a DataFrame only containing the expected features of data in the chosen country ''' self.assertIn('wounds', al.df_ctr_all('Japan').columns.values) self.assertNotIn('country', al.df_ctr_all('Japan').columns.values) self.assertEqual((45, 5), al.df_ctr_all('Japan').shape)
def test_ctr_stats(self): ''' test whether the ctr_stats function in AnalysisAndLinePlot module returns a DataFrame of analysis in the chosen country ''' self.assertEqual(45, al.ctr_stats('South Korea').loc['year', 'count']) self.assertEqual(2015, al.ctr_stats('South Korea').loc['year', 'max']) self.assertIn('casualties', al.ctr_stats('Austria').index.values) self.assertIn('25%', al.ctr_stats('Austria').columns.values)
def test_df_ctr(self): ''' test whether the df_ctr function in AnalysisAndLinePlot module returns a DataFrame only containing the data in the chosen country ''' self.assertIn('Norway', al.df_ctr('Norway').country.values) self.assertNotIn('Sweden', al.df_ctr('Norway').country.values) self.assertNotIn('eventid', al.df_ctr('The Whole World').columns.values)
def test_gtd_country_names(self): ''' test whether the gtd_country_names function in AnalysisAndLinePlot module returns the correct value ''' self.assertEqual(207, len(al.gtd_country_names())) self.assertIn('Greece', al.gtd_country_names()) self.assertIn('United States', al.gtd_country_names()) self.assertNotIn('America', al.gtd_country_names()) self.assertTrue('The Whole World', al.gtd_country_names()[0])
def test_drop93(self): ''' test whether the drop93 function in AnalysisAndLinePlot module returns a DataFrame without year 1993 ''' df_test93 = pd.DataFrame({ 'year': [1991, 1992, 1993, 1994, 1995], 'value': ['1', '2', '3', '4', '5'] }) self.assertNotIn(1993, al.drop93(df_test93).year.values) self.assertIn(1994, al.drop93(df_test93).year.values)
def test_analy_and_plot(self): ''' test whether expected expectations for inputting invalid feature values ''' with self.assertRaises(NoCountryDataError): al.analy_and_plot( 'America', 'wounds', 'white') # should be 'United States' instead of 'America' # 'Korea' is not included in GTD database # however, there are 'South Korea' and 'North Korea' with self.assertRaises(NoCountryDataError): al.analy_and_plot('Korea', 'casualties', 'black')
def test_df_occur_by_ctr(self): ''' test the df_occur_by_ctr function in AnalysisAndLinePlot module whether the return DataFrame is in expected format with correct values ''' self.assertEqual(['year', 'occurrences'], list(al.df_occur_by_ctr('Germany').columns)) self.assertEqual(['year', 'occurrences'], list(al.df_occur_by_ctr('The Whole World').columns)) self.assertEqual(pd.Index, type(al.df_occur_by_ctr('Italy').columns)) self.assertIn(2015, al.df_occur_by_ctr('The Whole World').year.values) self.assertNotIn( 1970, al.df_occur_by_ctr( 'Angola').year.values) # No attacks in Angola in 1970
def test_df_occur_by_ctr_allyears(self): ''' test the df_occur_by_ctr_allyears function in AnalysisAndLinePlot module whether the return DataFrame is in expected format with correct values ''' self.assertEqual(46, len(al.df_occur_by_ctr_allyears('France'))) self.assertEqual(46, len(al.df_occur_by_ctr_allyears('Australia'))) self.assertEqual(46, len(al.df_occur_by_ctr_allyears('Belgium'))) self.assertEqual(46, len(al.df_occur_by_ctr_allyears('Mexico'))) self.assertEqual(46, len(al.df_occur_by_ctr_allyears('The Whole World'))) self.assertEqual(0, al.df_occur_by_ctr_allyears('Angola').occurrences[0]) self.assertEqual( 0, al.df_occur_by_ctr_allyears('Angola').loc[0, 'occurrences']) self.assertNotIn( 2016, al.df_occur_by_ctr_allyears('United States').year.values)
def test_analy_ctr(self): ''' test whether the analy_ctr function in AnalysisAndLinePlot module returns a string ''' self.assertEqual(str, type(al.analy_ctr('Spain')))
def GTA_AL(): return al.Display_Your_Analysis_And_LinePlot()