Skip to content

Commit

Permalink
chore: menambahkan volume kubus (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: slowy07 <[email protected]>
  • Loading branch information
slowy07 authored Feb 19, 2024
1 parent 5bf8877 commit dd7c540
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
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

0 comments on commit dd7c540

Please sign in to comment.