From 3e4b4fc128f6bd485a95c90c509627fe4a09c5fd Mon Sep 17 00:00:00 2001
From: stedif <stefano.difrischia@inaf.it>
Date: Mon, 3 Oct 2022 16:25:46 +0200
Subject: [PATCH] L2SS-984: add subband change test

---
 .../default/devices/test_device_beamlet.py    | 25 +++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/devices/test_device_beamlet.py b/tangostationcontrol/tangostationcontrol/integration_test/default/devices/test_device_beamlet.py
index b5d7c9f85..ff8bcebde 100644
--- a/tangostationcontrol/tangostationcontrol/integration_test/default/devices/test_device_beamlet.py
+++ b/tangostationcontrol/tangostationcontrol/integration_test/default/devices/test_device_beamlet.py
@@ -11,6 +11,8 @@ from .base import AbstractTestBases
 
 from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy
 
+from tango import DevState
+
 import numpy
 import numpy.testing
 import time
@@ -41,8 +43,6 @@ class TestDeviceBeamlet(AbstractTestBases.TestDeviceBase):
         sdp_proxy = self.setup_sdp()
 
         self.proxy.initialise()
-        # TODO(Corne): Update test so effects of attribute are asserted L2SS-984
-        # self.proxy.subband_select_RW = [0] * 488
         self.proxy.on()
 
         # The subband frequency of HBA subband 0 is 200 MHz,
@@ -58,6 +58,27 @@ class TestDeviceBeamlet(AbstractTestBases.TestDeviceBase):
         expected_bf_weights = numpy.array([49152] * 192 * 488, dtype=numpy.uint32)
 
         numpy.testing.assert_almost_equal(expected_bf_weights, calculated_bf_weights)
+    
+    def test_subband_select_change(self):
+        # Setup configuration
+        sdp_proxy = self.setup_sdp()
+
+        # Change subband 
+        self.proxy.off()
+        self.proxy.initialise()
+        self.assertEqual(DevState.STANDBY, self.proxy.state())
+        self.proxy.subband_select_RW = [10] * 488
+        self.proxy.on()
+        self.assertEqual(DevState.ON, self.proxy.state())
+
+        # The subband frequency of HBA subband 10 is 201953125 Hz
+        # so its period is 4.95 ns ca, half period is 2.4758e-9
+        delays = numpy.array([[2.4758e-9] * 192] * 488)
+        calculated_bf_weights_subband_10 = self.proxy.calculate_bf_weights(delays.flatten())
+        
+        self.assertEqual(-2**14, c_short(49152).value) # check our calculations
+        expected_bf_weights_10 = numpy.array([49152] * 192 * 488, dtype=numpy.uint32)
+        numpy.testing.assert_almost_equal(expected_bf_weights_10, calculated_bf_weights_subband_10)
 
     def test_sdp_clock_change(self):
         # Setup configuration
-- 
GitLab