Commit 8aea6d13 authored by Gabriel Couture's avatar Gabriel Couture

Adding conversion integration tests

parent 20560eb4
Pipeline #190 passed with stage
in 9 seconds
# coding: utf-8
# author: gabriel couture
import unittest
from dvh import conversion
from dvh.dvh import DVH
AN_ABSOLUTE_DOSE_UNIT = 'GY'
A_RELATIVE_DOSE_UNIT = '%'
A_PRESCRIPTION_DOSE = 15
AN_ABSOLUTE_DOSE_LIST = list(range(0, 16))
A_RELATIVE_DOSE_LIST = [dose / A_PRESCRIPTION_DOSE for dose in AN_ABSOLUTE_DOSE_LIST]
AN_ABSOLUTE_VOLUME_LIST = list(range(0, 16))[::-1]
AN_ABSOLUTE_VOLUME_UNIT = 'CM3'
class TestConversion(unittest.TestCase):
def setUp(self) -> None:
self.a_dvh_with_absolute_doses = self._setup_dvh_with_absolute_doses()
self.a_dvh_with_relative_doses = self._setup_dvh_with_relative_doses()
def tearDown(self) -> None:
del self.a_dvh_with_absolute_doses
del self.a_dvh_with_relative_doses
def test_givenADVHWithAPrescriptionDose_whenCheckingIfDVHHasAPrescriptionDose_thenResultIsTrue(self):
self.a_dvh_with_absolute_doses.set_prescription_dose(A_PRESCRIPTION_DOSE)
result = conversion.is_dvh_has_a_prescription_dose(self.a_dvh_with_absolute_doses)
self.assertTrue(result)
def test_givenADVH_whenCheckingIfDVHHasAPrescriptionDose_thenResultIsFalse(self):
result = conversion.is_dvh_has_a_prescription_dose(self.a_dvh_with_absolute_doses)
self.assertFalse(result)
def test_givenADVHWithAbsoluteDosesAndPrescriptionDose_whenConvertingDVHDoseToRelative_thenResultIsADVHWithRelativeDoses(self):
self.a_dvh_with_absolute_doses.set_prescription_dose(A_PRESCRIPTION_DOSE)
result = conversion.convert_dvh_doses_to_relative(self.a_dvh_with_absolute_doses)
self.assertEqual(result.dose_unit, A_RELATIVE_DOSE_UNIT)
self.assertEqual(result.doses, A_RELATIVE_DOSE_LIST)
def test_givenADVHWithAbsoluteDosesAndNoPrescriptionDose_whenConvertingDVHDoseToRelative_thenRaisePrescriptionDoseIsMissingException(self):
self.assertRaises(
conversion.PrescriptionDoseIsMissingException,
lambda: conversion.convert_dvh_doses_to_relative(self.a_dvh_with_absolute_doses)
)
def test_givenADVHWithRelativeDoses_whenConvertingDVHDoseToRelative_thenResultIsTheSameDVHObject(self):
result = conversion.convert_dvh_doses_to_relative(self.a_dvh_with_relative_doses)
self.assertIs(result, self.a_dvh_with_relative_doses)
def test_givenADVHWithRelativeDosesAndPrescriptionDose_whenConvertingDVHDoseToAbsolute_thenResultIsADVHWithAbsoluteDoses(self):
self.a_dvh_with_relative_doses.set_prescription_dose(A_PRESCRIPTION_DOSE)
result = conversion.convert_dvh_doses_to_absolute(self.a_dvh_with_relative_doses)
self.assertEqual(result.dose_unit, AN_ABSOLUTE_DOSE_UNIT)
self.assertEqual(result.doses, AN_ABSOLUTE_DOSE_LIST)
def test_givenADVHWithRelativeDosesAndNoPrescriptionDose_whenConvertingDVHDoseToAbsolute_thenRaisePrescriptionDoseIsMissingException(self):
self.assertRaises(
conversion.PrescriptionDoseIsMissingException,
lambda: conversion.convert_dvh_doses_to_absolute(self.a_dvh_with_relative_doses)
)
def test_givenADVHWithAbsoluteDoses_whenConvertingDVHDoseToAbsolute_thenResultIsTheSameDVHObject(self):
result = conversion.convert_dvh_doses_to_absolute(self.a_dvh_with_absolute_doses)
self.assertIs(result, self.a_dvh_with_absolute_doses)
def _setup_dvh_with_absolute_doses(self) -> DVH:
return DVH(
doses=AN_ABSOLUTE_DOSE_LIST,
dose_unit=AN_ABSOLUTE_DOSE_UNIT,
volumes=AN_ABSOLUTE_VOLUME_LIST,
volume_unit=AN_ABSOLUTE_VOLUME_UNIT,
)
def _setup_dvh_with_relative_doses(self) -> DVH:
return DVH(
doses=A_RELATIVE_DOSE_LIST,
dose_unit=A_RELATIVE_DOSE_UNIT,
volumes=AN_ABSOLUTE_VOLUME_LIST,
volume_unit=AN_ABSOLUTE_VOLUME_UNIT,
)
......@@ -8,8 +8,8 @@ from dvh import conversion
from dvh.dvh import DVH
ABSOLUTE_DOSE_UNIT = 'GY'
RELATIVE_DOSE_UNIT = '%'
AN_ABSOLUTE_DOSE_UNIT = 'GY'
A_RELATIVE_DOSE_UNIT = '%'
A_PRESCRIPTION_DOSE = 15
......@@ -23,6 +23,10 @@ class TestConversion(unittest.TestCase):
self.a_dvh_with_absolute_doses = self._setup_dvh_with_absolute_doses()
self.a_dvh_with_relative_doses = self._setup_dvh_with_relative_doses()
def tearDown(self) -> None:
del self.a_dvh_with_absolute_doses
del self.a_dvh_with_relative_doses
def test_givenAbsoluteDoseListAndAPrescriptionDose_whenConvertingAbsoluteDosesToRelative_thenResultIsARelativeDoseList(self):
result = conversion.convert_absolute_doses_to_relative(AN_ABSOLUTE_DOSE_LIST, A_PRESCRIPTION_DOSE)
......@@ -51,7 +55,7 @@ class TestConversion(unittest.TestCase):
result = conversion.convert_dvh_doses_to_relative(self.a_dvh_with_absolute_doses)
self.assertEqual(result.dose_unit, RELATIVE_DOSE_UNIT)
self.assertEqual(result.dose_unit, A_RELATIVE_DOSE_UNIT)
self.assertEqual(result.doses, A_RELATIVE_DOSE_LIST)
def test_givenADVHWithAbsoluteDosesAndNoPrescriptionDose_whenConvertingDVHDoseToRelative_thenRaisePrescriptionDoseIsMissingException(self):
......@@ -72,7 +76,7 @@ class TestConversion(unittest.TestCase):
result = conversion.convert_dvh_doses_to_absolute(self.a_dvh_with_relative_doses)
self.assertEqual(result.dose_unit, ABSOLUTE_DOSE_UNIT)
self.assertEqual(result.dose_unit, AN_ABSOLUTE_DOSE_UNIT)
self.assertEqual(result.doses, AN_ABSOLUTE_DOSE_LIST)
def test_givenADVHWithRelativeDosesAndNoPrescriptionDose_whenConvertingDVHDoseToAbsolute_thenRaisePrescriptionDoseIsMissingException(self):
......@@ -93,10 +97,10 @@ class TestConversion(unittest.TestCase):
dvh = Mock()
dvh.doses = AN_ABSOLUTE_DOSE_LIST
dvh.dose_unit = ABSOLUTE_DOSE_UNIT
dvh.dose_unit = AN_ABSOLUTE_DOSE_UNIT
dvh.get_prescription_dose.return_value = -1
dvh.get_dose_unit.return_value = ABSOLUTE_DOSE_UNIT
dvh.get_dose_unit.return_value = AN_ABSOLUTE_DOSE_UNIT
dvh.get_doses.return_value = AN_ABSOLUTE_DOSE_LIST
return dvh
......@@ -105,10 +109,10 @@ class TestConversion(unittest.TestCase):
dvh = Mock()
dvh.doses = A_RELATIVE_DOSE_LIST
dvh.dose_unit = RELATIVE_DOSE_UNIT
dvh.dose_unit = A_RELATIVE_DOSE_UNIT
dvh.get_prescription_dose.return_value = -1
dvh.get_dose_unit.return_value = RELATIVE_DOSE_UNIT
dvh.get_dose_unit.return_value = A_RELATIVE_DOSE_UNIT
dvh.get_doses.return_value = A_RELATIVE_DOSE_LIST
return dvh
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment