From 1728a0220309f671d9226579225ed625057b38e4 Mon Sep 17 00:00:00 2001 From: Johannes Schumann <johannes.schumann@fau.de> Date: Sat, 3 Apr 2021 00:50:41 +0200 Subject: [PATCH] Add tests for geometry --- km3buu/tests/test_geometry.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 km3buu/tests/test_geometry.py diff --git a/km3buu/tests/test_geometry.py b/km3buu/tests/test_geometry.py new file mode 100644 index 0000000..9ebb154 --- /dev/null +++ b/km3buu/tests/test_geometry.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# coding=utf-8 +# Filename: test_output.py + +__author__ = "Johannes Schumann" +__copyright__ = "Copyright 2020, Johannes Schumann and the KM3NeT collaboration." +__credits__ = [] +__license__ = "MIT" +__maintainer__ = "Johannes Schumann" +__email__ = "jschumann@km3net.de" +__status__ = "Development" + +import unittest + +from km3buu.geometry import * + + +class TestGeneralGeometry(unittest.TestCase): + def test_abstract_init(self): + with self.assertRaises(TypeError) as ctx: + d = DetectorVolume() + + self.assertTrue('method random_pos' in str(ctx.exception)) + + +class TestSphere(unittest.TestCase): + def setUp(self): + self.detector_geometry = SphericalVolume(20, (2, 2, 2)) + + def test_volume(self): + volume = self.detector_geometry.volume + self.assertAlmostEqual(volume, 33510.32, 2) + + def test_random_pos(self): + for i in range(50): + pos = self.detector_geometry.random_pos() + assert pos[0] > -18.0 + assert pos[1] > -18.0 + assert pos[2] > -18.0 + assert pos[0] < 22.0 + assert pos[1] < 22.0 + assert pos[2] < 22.0 + + +class TestCan(unittest.TestCase): + def setUp(self): + self.detector_geometry = CanVolume() + + def test_volume(self): + volume = self.detector_geometry.volume + self.assertAlmostEqual(volume, 243604084.28, 2) -- GitLab