Skip to content
Snippets Groups Projects
Commit 6f8c9bc7 authored by WITTMANN Gregory's avatar WITTMANN Gregory
Browse files

Ajout du script de calcul du volume ainsi que ces tests associés

parent d3df4e3b
No related branches found
No related tags found
No related merge requests found
File added
File added
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
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
Volume de la sphère : 523.5987755982989
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment