diff --git a/__pycache__/calculVolumeSphere.cpython-311.pyc b/__pycache__/calculVolumeSphere.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..257d6432eaf36561e56c6081bc2f8d0f9f9fce5a Binary files /dev/null and b/__pycache__/calculVolumeSphere.cpython-311.pyc differ diff --git a/__pycache__/testCVS.cpython-311-pytest-7.4.4.pyc b/__pycache__/testCVS.cpython-311-pytest-7.4.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d34e568d5e7771d84a7659b9577725556c2ef8d6 Binary files /dev/null and b/__pycache__/testCVS.cpython-311-pytest-7.4.4.pyc differ diff --git a/calculVolumeSphere.py b/calculVolumeSphere.py new file mode 100644 index 0000000000000000000000000000000000000000..b7e0f1d8f536255935f7670f58e64024366f4b55 --- /dev/null +++ b/calculVolumeSphere.py @@ -0,0 +1,21 @@ + +import math + +def calculer_volume_sphere(rayon): + if rayon < 0: + raise ValueError("Le rayon ne peut pas être négatif.") + + volume = (4 * math.pi * rayon ** 3) / 3 + return volume + +def enregistrer_resultat_fichier(volume, fichier): + with open(fichier, 'w') as f: + f.write(f"Volume de la sphère : {volume}") + +def main(): + rayon = float(input("Rayon de la sphere : ")) + volume = calculer_volume_sphere(rayon) + enregistrer_resultat_fichier(volume, "volume.txt") + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/testCVS.py b/testCVS.py new file mode 100644 index 0000000000000000000000000000000000000000..cef8f26d3586dd2650dd68ba72d8032068b9e5be --- /dev/null +++ b/testCVS.py @@ -0,0 +1,8 @@ +from calculVolumeSphere import calculer_volume_sphere +import pytest + +def test_calculer_volume_sphere(): + assert calculer_volume_sphere(3) == pytest.approx(113.097335, rel=1e-6) + assert calculer_volume_sphere(0) == 0 + with pytest.raises(ValueError): + calculer_volume_sphere(-2) \ No newline at end of file diff --git a/volume.txt b/volume.txt new file mode 100644 index 0000000000000000000000000000000000000000..432334c55be7657510fdf34e95baea00e0a13016 --- /dev/null +++ b/volume.txt @@ -0,0 +1 @@ +Volume de la sph�re : 523.5987755982989 \ No newline at end of file