def test_from_parallel(self): dwf_a = DummyWaveform(duration=2.2, defined_channels={'A'}) dwf_b = DummyWaveform(duration=2.2, defined_channels={'B'}) dwf_c = DummyWaveform(duration=2.2, defined_channels={'C'}) self.assertIs(dwf_a, MultiChannelWaveform.from_parallel([dwf_a])) wf_ab = MultiChannelWaveform.from_parallel([dwf_a, dwf_b]) self.assertEqual(wf_ab, MultiChannelWaveform([dwf_a, dwf_b])) wf_abc = MultiChannelWaveform.from_parallel([wf_ab, dwf_c]) self.assertEqual(wf_abc, MultiChannelWaveform([dwf_a, dwf_b, dwf_c]))
def test_constant_default_impl(self): wf_non_const_a = DummyWaveform(defined_channels={'A'}, duration=3) wf_non_const_b = DummyWaveform(defined_channels={'B'}, duration=3) wf_const_c = ConstantWaveform(channel='C', amplitude=2.2, duration=3) wf_const_d = ConstantWaveform(channel='D', amplitude=3.3, duration=3) wf_const = MultiChannelWaveform.from_parallel((wf_const_c, wf_const_d)) wf_non_const = MultiChannelWaveform.from_parallel((wf_non_const_b, wf_non_const_a)) wf_mixed = MultiChannelWaveform.from_parallel((wf_non_const_a, wf_const_c)) assert_constant_consistent(self, wf_const) assert_constant_consistent(self, wf_non_const) assert_constant_consistent(self, wf_mixed) self.assertEqual(wf_const.constant_value_dict(), {'C': 2.2, 'D': 3.3}) self.assertIsNone(wf_non_const.constant_value_dict()) self.assertIsNone(wf_mixed.constant_value_dict()) self.assertEqual(wf_mixed.constant_value('C'), 2.2)
def test_init_several_channels(self) -> None: dwf_a = DummyWaveform(duration=2.2, defined_channels={'A'}) dwf_b = DummyWaveform(duration=2.2, defined_channels={'B'}) dwf_c = DummyWaveform(duration=2.3, defined_channels={'C'}) waveform = MultiChannelWaveform([dwf_a, dwf_b]) self.assertEqual({'A', 'B'}, waveform.defined_channels) self.assertEqual(TimeType.from_float(2.2), waveform.duration) with self.assertRaises(ValueError): MultiChannelWaveform([dwf_a, dwf_c]) with self.assertRaises(ValueError): MultiChannelWaveform([waveform, dwf_c]) with self.assertRaises(ValueError): MultiChannelWaveform((dwf_a, dwf_a)) dwf_c_valid = DummyWaveform(duration=2.2, defined_channels={'C'}) waveform_flat = MultiChannelWaveform.from_parallel((waveform, dwf_c_valid)) self.assertEqual(len(waveform_flat.compare_key), 3)