Kind stupid chekcing

This commit is contained in:
Cal Wing 2025-02-14 22:28:54 +01:00
parent a42e92d504
commit 9124ead993

70
a1.py
View File

@ -11,7 +11,7 @@ __email__ = "cal@wing.id.au"
__date__ = "14/02/2025"
__version__ = "1.0.0"
# Task 1 [Broken]
# Task 1
def determine_power_used(water_mass: float, elevation: float,
pumping_time: float, efficiency: float) -> float:
"""
@ -32,6 +32,8 @@ def determine_power_used(water_mass: float, elevation: float,
# Actual amount of energy needed based on eff
# Here an 85% eff means an extra 15% is needed to pump the water up
# [NOTE] I got stuck on this for a bit, unsure if it was my sleep deprived brain but took me
# me a bit to get the efficiency calc.
electrical_energy = potenital_energy / (efficiency/100) # J = J * SCALER
# Actual electrial power used to pump the water
@ -114,15 +116,52 @@ def calc_new_water_height(old_water_height: float, reservoir_area: float,
return new_water_height, water_mass_out
# Task 6
def calc_heights_water_out(initial_height: float, final_height: float,
reservoir_area: float, outlet_area: float,
time_inc: float
) -> tuple[tuple[float, ...], tuple[float, ...]]:
# Track the water height & mass
water_height, water_mass = [], []
# Do the first iteration
new_water_height, water_mass_out = \
calc_new_water_height(initial_height, reservoir_area,
outlet_area, time_inc)
# Store the new values
water_height.append(new_water_height)
water_mass.append(water_mass_out)
# Do the loop
while water_height[-1] > final_height:
new_water_height, water_mass_out = \
calc_new_water_height(water_height[-1], reservoir_area,
outlet_area, time_inc)
water_height.append(new_water_height)
water_mass.append(water_mass_out)
return water_height, water_mass
# See if I get what the task sheet wants
# [NOTE] It seems I am witing my own test suite :/ that wasn't the initention lol
def sheet_tasks():
import numpy as np
class NO_EVAL(type): pass # Whats an enum?
class TUPLE_EVAL(type): pass
TASKS = (
(determine_power_used, (5e6, 250, 8, 85), 500.9191176470588),
(determine_water_released, (300, 250, 8, 85), 2994495.4128440367),
(determine_cost_to_pump, (300, 8, 0.02), 48),
(calc_speed_at_outlet, (30,), 24.261079942986875),
(calc_new_water_height, (20, 40000, 1, 30), (19.985143183382704, 592567.1021442247)),
(calc_heights_water_out, (40, 5, 40000, 1, 30), ((39.97898928844613, 39.95798409574207, 39.93698442188801), (838016.4324684857, 837796.3120398963, 837576.1916037091), TUPLE_EVAL)),
)
for i, (task, args, expected) in enumerate(TASKS):
@ -134,12 +173,35 @@ def sheet_tasks():
foo = np.isclose(result, expected, 0.001)
print(f'{task.__qualname__}{args} -> {result} {"~=" if foo else "!="} {expected}')
print(f'Task is{"" if foo else " NOT"} close enough to expected result.')
# Run the task and print out what is is expected on a new line
elif isinstance(expected, (list, tuple)) and expected[-1] is NO_EVAL:
print(f'{task.__qualname__}{args} -> {result}')
print(f'Expected: {expected[:-1]}')
# Do a tuple eval
# [TODO] Do this, not complete
elif isinstance(expected, (list, tuple)) and expected[-1] is TUPLE_EVAL:
expected_result = expected[:-1]
comp_lenths = tuple(len(z) for z in expected_result)
#flag = True
#for k, j in enumerate(comp_lenths):
# for jj in range(j):
# if not np.isclose(result[k][jj], expected_result[k][jj], 0.001): break
# else:
# continue
# flag = False
# break
print(f'{task.__qualname__}{args} -> {tuple(result[z][:comp_lenths[z]] for z in range(len(result)))}')
print(f'Expected: {expected[:-1]}')
# Literal Comparison
elif expected is not None:
print(f'{task.__qualname__}{args} -> {result} {"==" if result == expected else "!="} {expected}')
print(f'Task{"" if result == expected else " NOT"} equal to expected result.')
print(f'Task is{"" if result == expected else " NOT"} equal to expected result.')
# Just run the task
else:
print(f'{task.__qualname__}{args} -> {result}')