From da9e633c0497aec59eeea0c99c56cb3d3fb90aac Mon Sep 17 00:00:00 2001 From: Cal Wing Date: Sun, 2 Mar 2025 11:39:58 +1000 Subject: [PATCH] Fix things --- a1.py | 6 +++--- generate_prams.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 generate_prams.py diff --git a/a1.py b/a1.py index d2f0821..5471cbb 100644 --- a/a1.py +++ b/a1.py @@ -1,5 +1,5 @@ # These could be from the std math lib, but I like the numpy ones better personally -from numpy import sin, cos, pi, sqrt, pow +from numpy import sin, cos, pi, sqrt # Pull a1 support from a1_support import GRAVITY_ACC, WATER_DENSITY, HELP_MESSAGE @@ -145,7 +145,7 @@ def calc_heights_water_out(initial_height: float, final_height: float, water_mass.append(water_mass_out) - return water_height, water_mass + return tuple(water_height), tuple(water_mass) # Task 7 def calc_energy_power(heights: tuple[float, ...], water_mass_outs: tuple[float, ...], @@ -167,7 +167,7 @@ def calc_energy_power(heights: tuple[float, ...], water_mass_outs: tuple[float, def calc_daily_profit(energy: tuple[float, ...], peak_tariff: float, off_peak_tariff: float, efficiency: float) -> float: - total_profit = sum(energy) * (peak_tariff - off_peak_tariff / pow(efficiency/100, 2)) + total_profit = sum(energy) * (peak_tariff - off_peak_tariff / ((efficiency/100)**2)) return total_profit diff --git a/generate_prams.py b/generate_prams.py new file mode 100644 index 0000000..0bd3870 --- /dev/null +++ b/generate_prams.py @@ -0,0 +1,37 @@ +import a1 + +import json, pprint, random + +# Enums, never heard of her +class PRIVOUS_TASK: pass +class EXACT: pass + +TESTS = ( + ( + 3, # Task + 5, # Number of tests + a1.determine_cost_to_pump, # The function to test + ( # The args and their ranges + ("gen_power", (float, 100, 600, 50)), # Type, min, max, inc + ("pumping_time", (float, 1, 10, 1)), + ("off_peak_tariff", (float, 0.01, 0.1, 0.01)), + ) + ), +) + +for task, iterations, function, args in TESTS: + print(f'\nTask {task}') + + args_used = [] + results = [] + for i in range(iterations): + this_arg = {} + for arg, vals in args: + this_arg[arg] = random.randrange(vals[1], vals[2], vals[3]) + + args_used.append(this_arg) + results.append(function(*args_used[-1])) + + pprint(args_used) + pprint(results) + \ No newline at end of file