Exemple #1
0
 def test_five_scalars_integer_float_whole_string_raises(self):
     with self.assertRaises(Exception) as context:
         five_scalars(good_integer, good_float, good_whole, good_positive,
                      bad_scalar)
     self.assertEqual(type(context.exception), TypeError)
     self.assertEqual(str(context.exception),
                      'Fifth argument must be an integer or a float')
def sinusoidal_roots_derivative_initial_value(first_constant, second_constant, third_constant, fourth_constant, initial_value, precision = 4):
    # Handle input errors
    five_scalars(first_constant, second_constant, third_constant, fourth_constant, initial_value)
    positive_integer(precision)

    # Create intermediary list and list to return
    roots = []
    result = []

    # Identify key ratio
    ratio = initial_value / (first_constant * second_constant)

    # Handle no roots
    if ratio > 1 or ratio < -1:
        result.append(None)
    
    # Handle multiple roots
    else:
        # Handle case in which initial value is zero
        if ratio == 0:
            roots = sinusoidal_roots_first_derivative(first_constant, second_constant, third_constant, fourth_constant, precision)
        
        # Handle general case
        else:
            radians = acos(ratio)
            periodic_radians = radians / second_constant
            periodic_unit = 2 * pi / second_constant
            initial = third_constant + periodic_radians
            roots = generate_elements(initial, periodic_unit, precision)

            # Handle roots that bounce on the x-axis
            if ratio == 1 or ratio == -1:
                pass

            # Handle roots that cross the x-axis
            else:
                alternative_initial = third_constant + periodic_unit - periodic_radians
                generated_elements = generate_elements(alternative_initial, periodic_unit, precision)
                roots.extend(generated_elements)
        
        # Separate numerical roots, string roots, and None results
        separated_roots = separate_elements(roots)
        numerical_roots = separated_roots['numerical']
        other_roots = separated_roots['other']
        
        # Sort numerical roots
        sorted_roots = sorted_list(numerical_roots)

        # Round numerical roots
        rounded_roots = rounded_list(sorted_roots, precision)
        
        # Sort other_roots
        sorted_other_roots = sorted_strings(other_roots)

        # Combine numerical and non-numerical roots
        result.extend(rounded_roots + sorted_other_roots)
    
    # Return result
    return result
def sinusoidal_roots_initial_value(first_constant, second_constant, third_constant, fourth_constant, initial_value, precision = 4):
    # Handle input errors
    five_scalars(first_constant, second_constant, third_constant, fourth_constant, initial_value)
    positive_integer(precision)

    # Determine roots given an initial value
    result = sinusoidal_roots(first_constant, second_constant, third_constant, fourth_constant - initial_value, precision)
    return result
def cubic_roots_derivative_initial_value(first_constant,
                                         second_constant,
                                         third_constant,
                                         fourth_constant,
                                         initial_value,
                                         precision=4):
    # Handle input errors
    five_scalars(first_constant, second_constant, third_constant,
                 fourth_constant, initial_value)
    positive_integer(precision)

    # Determine roots of derivative given an initial value
    result = quadratic_roots(3 * first_constant, 2 * second_constant,
                             third_constant - initial_value, precision)
    return result
Exemple #5
0
 def test_five_scalars_integer_float_whole_positive(self):
     five_scalars_integer_float_whole_positive = five_scalars(
         good_integer, good_float, good_whole, good_positive, good_integer)
     self.assertEqual(
         five_scalars_integer_float_whole_positive,
         'First, second, third, fourth, and fifth arguments are all integers or floats'
     )