def test_add_instruction_already_compiled(self) -> None: block = InstructionBlock() wf1 = DummyWaveform() wf2 = DummyWaveform() block.add_instruction_exec(wf1) block.compile_sequence() block.add_instruction_exec(wf2) sequence = block.compile_sequence() expected_sequence = [EXECInstruction(wf1), EXECInstruction(wf2), STOPInstruction()] self.assertEqual(expected_sequence, sequence)
def test_render(self) -> None: wf1 = DummyWaveform(duration=19) wf2 = DummyWaveform(duration=21) block = InstructionBlock() block.add_instruction_exec(wf1) block.add_instruction_exec(wf2) plotter = Plotter(sample_rate=0.5) times, voltages = plotter.render(block.compile_sequence()) wf1_expected = [([0, 2, 4, 6, 8, 10, 12, 14, 16, 18], 0)] wf2_expected = [([20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40], 1)] expected_result = list(range(0, 41, 2)) self.assertEqual(wf1_expected, wf1.sample_calls) self.assertEqual(wf2_expected, wf2.sample_calls) self.assertEqual(expected_result, list(times)) self.assertEqual(expected_result, list(voltages))
def __verify_block(self, block: InstructionBlock, expected_instructions: InstructionSequence, expected_compiled_instructions: InstructionSequence) -> None: self.assertEqual(len(expected_instructions), len(block)) self.assertEqual(expected_instructions, block.instructions) self.assertEqual(expected_compiled_instructions, block.compile_sequence())
def test_render_unsupported_instructions(self) -> None: block = InstructionBlock() block.add_instruction(DummyInstruction()) plotter = Plotter() with self.assertRaises(NotImplementedError): plotter.render(block.compile_sequence())