From 97e5b77371debcf88e0ff3ceb2b847b1ce950fa2 Mon Sep 17 00:00:00 2001 From: scm929 <157171908+scm929@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:15:17 -0500 Subject: [PATCH] Add comments to test_comparison.py --- app/calculation/test_comparison.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/calculation/test_comparison.py b/app/calculation/test_comparison.py index 95eab3b..c558879 100644 --- a/app/calculation/test_comparison.py +++ b/app/calculation/test_comparison.py @@ -2,39 +2,41 @@ from unittest.mock import patch import comparison +# since this function randomly chooses a comparison, we need to force which one is picked so we can test and output. We use 'mock' +# to define which case is chosen class test_emissions_comparison_text(unittest.TestCase): @patch('comparison.random.choice') def test_tree_comparison(self, mock_choice): - mock_choice.return_value = 'tree_comparison' + mock_choice.return_value = 'tree_comparison' #using mock the say that 'tree_comparison' was "randomly chosen" metric_tons_co2_emitted = 5.5 output = comparison.get_emissions_comparison_text(metric_tons_co2_emitted) - self.assertEqual(output, "It will take 275 trees approximately 1 year to remove this CO2 from the atmosphere.") + self.assertEqual(output, "It will take 275 trees approximately 1 year to remove this CO2 from the atmosphere.") #this is the expected output assuming that the jet trip emitted 5.5 mt CO2 @patch('comparison.random.choice') def test_LA_NY_comparison(self, mock_choice): - mock_choice.return_value = 'LA_NY_drive_comparison' + mock_choice.return_value = 'LA_NY_drive_comparison' #using mock the say that 'LA_NY_drive_comparison' was "randomly chosen" metric_tons_co2_emitted = 5.5 output = comparison.get_emissions_comparison_text(metric_tons_co2_emitted) - self.assertEqual(output, "You would have to drive from LA to NY 5 times to emit this same amount.") + self.assertEqual(output, "You would have to drive from LA to NY 5 times to emit this same amount.") #expected output given a 5.5 mt co2 jet trip emission @patch('comparison.random.choice') def test_average_american_comparison_less_than_one_year(self, mock_choice): - mock_choice.return_value = 'average_american_emissions_comparison' + mock_choice.return_value = 'average_american_emissions_comparison' #using mock the say that 'average_american_emissions_comparison' was "randomly chosen" metric_tons_co2_emitted = 5.5 output = comparison.get_emissions_comparison_text(metric_tons_co2_emitted) - self.assertEqual(output, "It would take an average American 4 months to emit the same amount.") + self.assertEqual(output, "It would take an average American 4 months to emit the same amount.") #expected output given a 5.5 mt co2 jet trip emission, confirming output is in months @patch('comparison.random.choice') def test_average_american_comparison_one_year(self, mock_choice): - mock_choice.return_value = 'average_american_emissions_comparison' + mock_choice.return_value = 'average_american_emissions_comparison' #using mock the say that 'average_american_emissions_comparison' was "randomly chosen" metric_tons_co2_emitted = 14.5 output = comparison.get_emissions_comparison_text(metric_tons_co2_emitted) - self.assertEqual(output, "It would take an average American 1.0 years to emit the same amount.") + self.assertEqual(output, "It would take an average American 1.0 years to emit the same amount.") #confirming correct output in years for 1 year worth of emissons @patch('comparison.random.choice') def test_average_american_comparison_more_than_one_year(self, mock_choice): - mock_choice.return_value = 'average_american_emissions_comparison' + mock_choice.return_value = 'average_american_emissions_comparison' #using mock the say that 'average_american_emissions_comparison' was "randomly chosen" metric_tons_co2_emitted = 20 output = comparison.get_emissions_comparison_text(metric_tons_co2_emitted) - self.assertEqual(output, "It would take an average American 1.38 years to emit the same amount.") \ No newline at end of file + self.assertEqual(output, "It would take an average American 1.38 years to emit the same amount.") #confirming output for > 1 years worth of emissions