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

chore: menambahkan fungsi volume kubus #65

Merged
merged 1 commit into from
Feb 19, 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
4 changes: 2 additions & 2 deletions OpenSeries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from OpenSeries.dasar import bulat, akar, tan_hiperbolik
from OpenSeries.dasar import bulat, akar, tan_hiperbolik, volume_kubus

if __name__ == "__main__":
list_dasar: list = [bulat, akar, tan_hiperbolik]
list_dasar: list = [bulat, akar, tan_hiperbolik, volume_kubus]
for tipe in range(len(list_dasar)):
print(type(list_dasar[tipe]))
21 changes: 21 additions & 0 deletions OpenSeries/dasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ def tan_hiperbolik(x: np.ndarray) -> Union[np.ndarray, error.ErrorTipeData]:
if not isinstance(x, np.ndarray):
return error.ErrorTipeData(["numpy.ndarray"])
return (2 / (1 + np.exp(-2 * x))) - 1


def volume_kubus(
panjang_sisi: Union[float, int],
) -> Union[float, int, error.ErrorTipeData, error.Error]:
"""
menghitung volume kubus

Parameter:
panjang_sisi (int atau float): sisi yang akan dihitung

return:
float atau int: hasil dari perhitungan
ErrorTipeData: error jika diberikan tipe data yang salah
Error: error jika nilai yang diberikan negatif
"""
if not isinstance(panjang_sisi, (float, int)):
return error.ErrorTipeData(["float", "int"])
if panjang_sisi < 0:
return error.Error("panjang_sisi hanya menerima nilai positif")
return pow(panjang_sisi, 3)
20 changes: 20 additions & 0 deletions testing/dasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ def test_tan_invalid_input(self):
input = 5
with self.assertRaises(error.ErrorTipeData):
raise opseries.tan_hiperbolik(input)


class TestVolumeKubus(unittest.TestCase):
def test_volume_nilai_integer(self):
hasil = opseries.volume_kubus(3)
self.assertEqual(hasil, 27)

def test_volume_nilai_float(self):
hasil = opseries.volume_kubus(3.0)
self.assertEqual(hasil, 27.0)

def test_nilai_invalid_str(self):
hasil = opseries.volume_kubus("20")
with self.assertRaises(error.ErrorTipeData):
raise hasil

def test_nilai_invalid_minus(self):
hasil = opseries.volume_kubus(-1)
with self.assertRaises(error.Error):
raise hasil
4 changes: 2 additions & 2 deletions testing/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from testing.statistika_test import TestFungsiEntropy, TestFungiStandardDeviasi

from testing.dasar import TestBulat, TestAkar, TestTanHiperbolik
from testing.dasar import TestBulat, TestAkar, TestTanHiperbolik, TestVolumeKubus

if __name__ == "__main__":
testing_matematika: list = [
Expand Down Expand Up @@ -84,7 +84,7 @@
TestAngkaSegitiga,
]

testing_dasar: list = [TestBulat, TestAkar, TestTanHiperbolik]
testing_dasar: list = [TestBulat, TestAkar, TestTanHiperbolik, TestVolumeKubus]

all_tests = unittest.TestSuite()

Expand Down