From c50691aad31e91dadf85c4e6008fde90f0bf00f5 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 31 Aug 2022 11:16:03 +0200
Subject: [PATCH] L2SS-917: Improved tests to detect 90/180 degree errors

---
 .../test/devices/test_beamlet_device.py       | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/test/devices/test_beamlet_device.py b/tangostationcontrol/tangostationcontrol/test/devices/test_beamlet_device.py
index 81b34f00e..e7b82ec29 100644
--- a/tangostationcontrol/tangostationcontrol/test/devices/test_beamlet_device.py
+++ b/tangostationcontrol/tangostationcontrol/test/devices/test_beamlet_device.py
@@ -65,15 +65,21 @@ class TestBeamletDevice(base.TestCase):
         self.assertEqual(to_complex(bf_weights[1][2]), -1 + 0j, msg=f"bf_weights = {bf_weights}")
 
     def test_calculate_bf_weights_actual_numbers(self):
+        # we test phase offsets with 90 degree increments to weed out:
+        #  - sign errors (-1-2j instead of 1+2j == 180 degree offset)
+        #  - complex conjugation errors (1-2j instead of 1+2j == 180 degree offset)
+        #  - real/imaginary swap errors (2+1j instead of 1+2j == 90 degree offset)
+        #
+        # NB: -180 degree rotation == +180 degree rotation, so we need 90 degree
+        #     offsets to detect 180 degree errors as well.
+
         # 2 beamlets, 3 antennas. The antennas are 1 second apart.
         delays = numpy.array([
-            [0.0, 2.5e-9, 5.0e-9]
+            [0.0, 1.25e-9, 2.5e-9, 3.75e-9, 5.0e-9]
         ])
 
-        # the frequency of the signal is 1.0 Hz and 0.5 Hz respectively,
-        # so the antennas will be either in phase or in opposite phase
         beamlet_frequencies = numpy.array([
-            [200e6, 200e6, 200e6]
+            [200e6, 200e6, 200e6, 200e6, 200e6]
         ])
 
         bf_weights = Beamlet._calculate_bf_weights(delays, beamlet_frequencies)
@@ -81,8 +87,10 @@ class TestBeamletDevice(base.TestCase):
         self.assertEqual(delays.shape, bf_weights.shape)
 
         self.assertEqual(to_complex(bf_weights[0][0]),  1 + 0j, msg=f"bf_weights = {bf_weights}")
-        self.assertEqual(to_complex(bf_weights[0][1]), -1 + 0j, msg=f"bf_weights = {bf_weights}")
-        self.assertEqual(to_complex(bf_weights[0][2]),  1 + 0j, msg=f"bf_weights = {bf_weights}")
+        self.assertEqual(to_complex(bf_weights[0][1]),  0 - 1j, msg=f"bf_weights = {bf_weights}")
+        self.assertEqual(to_complex(bf_weights[0][2]), -1 + 0j, msg=f"bf_weights = {bf_weights}")
+        self.assertEqual(to_complex(bf_weights[0][3]),  0 + 1j, msg=f"bf_weights = {bf_weights}")
+        self.assertEqual(to_complex(bf_weights[0][4]),  1 + 0j, msg=f"bf_weights = {bf_weights}")
 
     def test_subband_frequencies(self):
         subbands = numpy.array([
-- 
GitLab