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

Barometrik #20

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions OpenSeries/fisika.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,25 @@ def hukum_ohm(i: Union[float, int], r: Union[float, int]) -> Union[float, int, s
return error.error_tipe_data(["float", "int"])
else:
return i * r


def ketinggian_barometrik(tekanan: float) -> Union[float, str]:
"""
fungsi untuk menghitung perkiraan ketinggian berdasarkan dari
tekanan udara yang menggunakan rumus barometrik

Parameter:
tekanan (float): tekanan udara
"""
if not isinstance(tekanan, float):
return error.error_tipe_data(["float"])
else:
if tekanan > 101325:
return error.error_format(
"nilai lebih tinggi dari tekanan di permukaan laut"
)
if tekanan < 0:
return error.error_format("tekanan atmosfir tidak bisa negatif")
else:
hasil = 44_330 * (1 - (tekanan / 101_325) ** (1 / 5.5255))
return hasil
7 changes: 7 additions & 0 deletions example/fisika/tekanan_barometrik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import OpenSeries.fisika as fisika

# tekanan udara
tekanan = 100_000.0
# memanggil fungsi dari ketinggian barometrik
hasil = fisika.ketinggian_barometrik(tekanan)
print(f"tekanan: {tekanan} Pa, Ketinggian adalah: {hasil} meter")
23 changes: 23 additions & 0 deletions testing/fisika_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ def test_valid_input(self):
def test_invalid_input_mix_tipe_data(self):
hasil = fisika.energi_kinetik("3", 4.5)
self.assertEqual(hasil, error.error_tipe_data(["int", "float"]))


class TestKetinggianBarometrik(unittest.TestCase):
def test_valid_input_tekanan(self):
hasil = fisika.ketinggian_barometrik(101325.0)
self.assertIsInstance(hasil, float)

def test_tekanan_lebih_besar_daripada_air(self):
hasil = fisika.ketinggian_barometrik(110000.0)
self.assertEqual(
hasil,
error.error_format("nilai lebih tinggi dari tekanan di permukaan laut"),
)

def test_tekanan_angka_negatif(self):
hasil = fisika.ketinggian_barometrik(-820.3)
self.assertEqual(
hasil, error.error_format("tekanan atmosfir tidak bisa negatif")
)

def test_tekanan_tipe_data_salah(self):
hasil = fisika.ketinggian_barometrik("12")
self.assertEqual(hasil, error.error_tipe_data(["float"]))
2 changes: 2 additions & 0 deletions testing/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TestPercepatan,
TestGerakLurusBeraturan,
TestEnergiKinetik,
TestKetinggianBarometrik,
)

from testing.statistika_test import TestFungsiEntropy, TestFungiStandardDeviasi
Expand All @@ -42,6 +43,7 @@
TestPercepatan,
TestGerakLurusBeraturan,
TestEnergiKinetik,
TestKetinggianBarometrik,
]

testing_statistika: list = [
Expand Down
Loading