Пример #1
0
class TestWaveStatistics(unittest.TestCase):
    """
    Test WaveStatistics class
    """

    def clean_state(self):
        self.direction = None
        self.volume = None
        self.wave_statistic = None

    def setUp(self):
        self.clean_state()
        self.direction = Direction.from_xyz((2.0, 3.0, 4.0))
        self.volume = 10.0

    def tearDown(self):
        self.clean_state()

    def test_wave_statistics_construction(self):
        self.when_wave_statistic_constructed()
        self.then_wave_statistic_has_expected_values()

    def when_wave_statistic_constructed(self):
        self.wave_statistic = WaveStatistics(self.volume, self.direction)

    def then_wave_statistic_has_expected_values(self):
        self.assertEqual(self.volume, self.wave_statistic.volume)
        self.assertTupleEqual(self.direction.xyz, self.wave_statistic.central_direction.xyz)
        self.assertTupleEqual((20.0, 30.0, 40.0),
                              self.wave_statistic.volume_weighted_direction.xyz)
        self.assertTupleEqual(self.direction.normalized().xyz,
                              self.wave_statistic.normalized_direction.xyz)

    def test_wave_statistics_accumulate(self):
        self.when_wave_statistic_constructed()
        self.when_wave_statistic_added()
        self.when_wave_statistic_added()
        self.assertEqual(3.0 * self.volume, self.wave_statistic.volume)
        self.assertTupleEqual(self.direction.normalized().xyz,
                              self.wave_statistic.normalized_direction.xyz)

    def when_wave_statistic_added(self):
        self.wave_statistic.add(WaveStatistics(self.volume, self.direction))
Пример #2
0
 def when_wave_statistic_constructed(self):
     self.wave_statistic = WaveStatistics(self.volume, self.direction)