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

feat: menambahkan fungsi euler pi #22

Merged
merged 1 commit into from
Jan 26, 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: 21 additions & 1 deletion OpenSeries/matematika.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def fpb(
return pesan_error.error_tipe_data(["float", "int"])


def faktor_prima(n: int) -> Union[list[int], str]:
def faktor_prima(n: int) -> Union[list, str]:
"""
membuat fungsi untuk mengurutkan nilai faktor prima

Expand Down Expand Up @@ -346,3 +346,23 @@ def transpose_matriks(
return [
[matriks[j][i] for j in range(len(matriks))] for i in range(len(matriks[0]))
]


def euler_pi(n: int) -> Union[int, float, str]:
"""
menghitung fungsi dari euler pi

parameter:
n (int): bilangan untuk menghitung fungsi dari euler phi
"""
if not isinstance(n, int):
return pesan_error.error_tipe_data(["int"])
else:
if n <= 0:
return pesan_error.error_format(
"nilai dari bilangan tidak boleh negatif atau 0"
)
s = n
for x in set(faktor_prima(n)):
s *= (x - 1) / x
return s
2 changes: 2 additions & 0 deletions testing/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
TestFPB,
TestFaktorPrima,
TestMatriksTranspose,
TestFungsiEuler,
)

from testing.fisika_test import (
Expand All @@ -36,6 +37,7 @@
TestFPB,
TestFaktorPrima,
TestMatriksTranspose,
TestFungsiEuler,
]

testing_fisika: list = [
Expand Down
22 changes: 22 additions & 0 deletions testing/matematika_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,25 @@ def test_valid_input(self):
ekspetasi = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
hasil = matematika.transpose_matriks(matriks_a)
self.assertEqual(hasil, ekspetasi)


class TestFungsiEuler(unittest.TestCase):
def test_nilai_positif(self):
hasil = matematika.euler_pi(100)
self.assertEqual(hasil, 40.0)

def test_nilai_tidak_integer(self):
hasil = matematika.euler_pi(3.14)
self.assertEqual(hasil, error.error_tipe_data(["int"]))

def test_nilai_negatif(self):
hasil = matematika.euler_pi(-20)
self.assertEqual(
hasil, error.error_format("nilai dari bilangan tidak boleh negatif atau 0")
)

def test_nilai_nol(self):
hasil = matematika.euler_pi(0)
self.assertEqual(
hasil, error.error_format("nilai dari bilangan tidak boleh negatif atau 0")
)
Loading