Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests electronics/electric_conductivity.py #9943 #12437

Merged
merged 9 commits into from
Dec 30, 2024
Merged
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
* [Prefix Conversions](conversions/prefix_conversions.py)
* [Prefix Conversions String](conversions/prefix_conversions_string.py)
* [Pressure Conversions](conversions/pressure_conversions.py)
* [Rec To Pol](conversions/rec_to_pol.py)
cclauss marked this conversation as resolved.
Show resolved Hide resolved
* [Rgb Cmyk Conversion](conversions/rgb_cmyk_conversion.py)
* [Rgb Hsv Conversion](conversions/rgb_hsv_conversion.py)
* [Roman Numerals](conversions/roman_numerals.py)
Expand Down
33 changes: 33 additions & 0 deletions conversions/rec_to_pol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import doctest
cclauss marked this conversation as resolved.
Show resolved Hide resolved
import math


def rec_to_pol(real: float, img: float) -> tuple:
cclauss marked this conversation as resolved.
Show resolved Hide resolved
"""
https://en.wikipedia.org/wiki/Polar_coordinate_system

>>> rec_to_pol(5,-5)
(7.07, -45.0)
>>> rec_to_pol(-1,1)
(1.41, 135.0)
>>> rec_to_pol(-1,-1)
(1.41, -135.0)
>>> rec_to_pol(1e-10,1e-10)
(0.0, 45.0)
>>> rec_to_pol(-1e-10,1e-10)
(0.0, 135.0)
>>> rec_to_pol(9.75,5.93)
(11.41, 31.31)
>>> rec_to_pol(10000,99999)
(100497.76, 84.29)

cclauss marked this conversation as resolved.
Show resolved Hide resolved
"""

mod = round(math.sqrt((real**2) + (img**2)), 2)

ang = round(math.degrees(math.atan2(img, real)), 2)
return (mod, ang)


if __name__ == "__main__":
cclauss marked this conversation as resolved.
Show resolved Hide resolved
doctest.testmod()
20 changes: 20 additions & 0 deletions electronics/electric_conductivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ def electric_conductivity(
('conductivity', 5.12672e-14)
>>> electric_conductivity(conductivity=1000, electron_conc=0, mobility=1200)
('electron_conc', 5.201506356240767e+18)
>>> electric_conductivity(conductivity=-10, electron_conc=100, mobility=0)
Traceback (most recent call last):
...
ValueError: Conductivity cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=-10, mobility=0)
Traceback (most recent call last):
...
ValueError: Electron concentration cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=0, mobility=-10)
Traceback (most recent call last):
...
ValueError: mobility cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=0, mobility=0)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
>>> electric_conductivity(conductivity=50, electron_conc=200, mobility=300)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
"""
if (conductivity, electron_conc, mobility).count(0) != 1:
raise ValueError("You cannot supply more or less than 2 values")
Expand Down
Loading