summaryrefslogtreecommitdiffstats
path: root/lab_control/test
diff options
context:
space:
mode:
Diffstat (limited to 'lab_control/test')
-rw-r--r--lab_control/test/frequency_response_measurement_test.py25
-rw-r--r--lab_control/test/mock_lab.py17
2 files changed, 28 insertions, 14 deletions
diff --git a/lab_control/test/frequency_response_measurement_test.py b/lab_control/test/frequency_response_measurement_test.py
index caea62a..5a73b3e 100644
--- a/lab_control/test/frequency_response_measurement_test.py
+++ b/lab_control/test/frequency_response_measurement_test.py
@@ -11,6 +11,13 @@ def mockLab():
def uut(mockLab):
return FrequencyResponseMeasurement()
+def test_frequencyResponseDefaults(uut):
+ assert uut.minFrequency == 20e0
+ assert uut.maxFrequency == 16e3
+ assert uut.steps == 50
+ assert uut.functionGeneratorChannel == 1
+ assert uut.oscilloscopeChannel == 1
+
def test_frequencyResponseRamp(mockLab, uut):
uut.minFrequency = 100.0
uut.maxFrequency = 200.0
@@ -18,18 +25,22 @@ def test_frequencyResponseRamp(mockLab, uut):
uut.functionGeneratorChannel = 1
uut.oscilloscopeChannel = 1
- # Expect a ramp response from 0 to 2 V
- minAmplitude = 0.0
- maxAmplitude = 2.0
+ # Expect a ramp response from 0.5 to 1.5 * input amplitude
+ inputAmplitude = 1.0
+ minScale = 0.5
+ maxScale = 1.5
- def amplitudeFunction(f: float) -> float:
+ def testFunction(f: float) -> float:
assert f >= uut.minFrequency and f <= uut.maxFrequency
frequencyPu = (f - uut.minFrequency) / (uut.maxFrequency - uut.minFrequency)
- return minAmplitude + maxAmplitude * frequencyPu
+ return minScale + maxScale * frequencyPu
mockLab.connectChannels(uut.functionGeneratorChannel, uut.oscilloscopeChannel)
- mockLab.setAmplitudeFunction(uut.oscilloscopeChannel, amplitudeFunction)
- expectedData = [(f, amplitudeFunction(f)) for f in [100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0]]
+ mockLab.setTestFunction(uut.oscilloscopeChannel, testFunction)
+ mockLab.setAmplitude(uut.functionGeneratorChannel, inputAmplitude)
+ mockLab.setOn(uut.functionGeneratorChannel)
+
+ expectedData = [(f, testFunction(f) * inputAmplitude) for f in [100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0]]
assert not uut.measurementDone
assert uut.data == None
diff --git a/lab_control/test/mock_lab.py b/lab_control/test/mock_lab.py
index 718f319..40893ca 100644
--- a/lab_control/test/mock_lab.py
+++ b/lab_control/test/mock_lab.py
@@ -12,8 +12,8 @@ class MockLab(FunctionGenerator, Oscilloscope):
class OscChannelState:
def __init__(self):
- self.amplitudeFunction = None
- self.fgChannel = None
+ self.testFunction = None
+ self.connectedChannel = None
def __init__(self):
self.fgChannels = [MockLab.FGChannelState() for i in range(0, 2)]
@@ -35,8 +35,11 @@ class MockLab(FunctionGenerator, Oscilloscope):
pass
def measureAmplitude(self, channel: int) -> float:
- fgChannel = self.oscChannels[channel - 1].fgChannel
- return self.oscChannels[channel - 1].amplitudeFunction(self.fgChannels[fgChannel].frequency)
+ fgChannel = self.oscChannels[channel - 1].connectedChannel
+ frequency = fgChannel.frequency if fgChannel.on else 0.0
+ amplitude = fgChannel.amplitude if fgChannel.on else 0.0
+
+ return self.oscChannels[channel - 1].testFunction(frequency) * amplitude
def measurePeakToPeak(self, channel: int) -> float:
pass
@@ -47,8 +50,8 @@ class MockLab(FunctionGenerator, Oscilloscope):
def measureFrequency(self, channel: int) -> float:
pass
- def setAmplitudeFunction(self, channel: int, f: Callable[[float], float]) -> None:
- self.oscChannels[channel - 1].amplitudeFunction = f
+ def setTestFunction(self, channel: int, f: Callable[[float], float]) -> None:
+ self.oscChannels[channel - 1].testFunction = f
def connectChannels(self, fg: int, osc: int) -> None:
- self.oscChannels[osc - 1].fgChannel = fg - 1
+ self.oscChannels[osc - 1].connectedChannel = self.fgChannels[fg - 1]