Example #1
0
    def test_exception_is_raised_when_curve_data_contains_string(self):
        # Assume
        example_curve_data = [[1, 2, 200], [2, 'a string', 400], [3, 4, 600],
                              [4, 5, 800]]

        # Assert
        with self.assertRaises(Exception):
            utils.vulnerability_curve(example_curve_data)
Example #2
0
    def test_min_and_max_values_are_returned_correctly_from_vulnerability_curve_data(
            self):
        # Assume
        example_curve_data = [[1, 2, 200], [2, 3, 400], [3, 4, 600],
                              [4, 5, 800]]

        # Action
        curve = utils.vulnerability_curve(example_curve_data)

        # Assert
        self.assertTrue(curve.max == 5)
        self.assertTrue(curve.min == 1)
Example #3
0
def run_script(input_vulnerability_curve: str, input_depths: str, output_file: str, currency: str):
    '''Use this function if importing damagecalc for another script.'''

    vc = utils.vulnerability_curve(input_vulnerability_curve)
    total_cost, count, ignored = utils.calculate_damage_costs(
        input_depths, output_file, vc)

    print('''
    -----------------------------
    Total Cost: {}{:,.2f}
    Depth Values Processed: {}
    Skipped Values: {} (This should always be zero)
    -----------------------------
    '''.format(currency, total_cost, count, ignored))
Example #4
0
    def setUp(self):
        # region #? csv input paths
        self.test_data_root = './tests/data'

        self.normal_depths = join(self.test_data_root, 'normal_depths.csv')
        self.inconsistent_data_rows = join(self.test_data_root,
                                           'inconsistent_data_rows.csv')
        self.non_numerical_values = join(self.test_data_root,
                                         'non_numerical_values.csv')
        self.out_of_range_values = join(self.test_data_root,
                                        'out_of_range_values.csv')

        self.normal_vulnerability_curve = join(
            self.test_data_root, 'normal_vulnerability_curve.csv')
        self.nonsense_vulnerability_curve = join(
            self.test_data_root, 'nonsense_vulnerability_curve.csv')
        # endregion

        self.vulnerability_curve_class = utils.vulnerability_curve(
            self.normal_vulnerability_curve)

        self.test_output = join(self.test_data_root, 'testing.csv')
Example #5
0
    def test_exception_is_raised_when_invalid_data_is_passed_to_vulnerability_curve(
            self):

        with self.assertRaises(ValueError):
            utils.vulnerability_curve(self.nonsense_vulnerability_curve)