public void OnNewFrameCreatesOverflowSample(int overflow, int[] tacts, float?sample)
        {
            // --- Arrange
            var spectrum     = new SpectrumBeepTestMachine();
            var beeperDevice = new BeeperDevice();

            beeperDevice.OnAttachedToVm(spectrum);
            var initialBit = false;

            // --- Act
            foreach (var tact in tacts)
            {
                spectrum.SetCurrentCpuTact(tact);
                beeperDevice.ProcessEarBitValue(false, initialBit);
                initialBit = !initialBit;
            }
            spectrum.SetCurrentCpuTact(69888 + overflow);
            beeperDevice.OnFrameCompleted();
            var overflowBefore = beeperDevice.Overflow;

            beeperDevice.OnNewFrame();

            // --- Assert
            beeperDevice.SamplesIndex.ShouldBe(sample == null ? 0 : 1);
            overflowBefore.ShouldBe(overflow);
            beeperDevice.Overflow.ShouldBe(0);
            if (sample.HasValue)
            {
                beeperDevice.AudioSamples[0].ShouldBe(sample.Value);
            }
        }
        public void SampleLengthIsCalculatedProperly(int frames, int[] lenghts)
        {
            // --- Arrange
            var spectrum     = new SpectrumBeepTestMachine();
            var beeperDevice = new BeeperDevice();

            beeperDevice.OnAttachedToVm(spectrum);

            // --- Act/Assert
            for (var i = 1; i <= frames; i++)
            {
                spectrum.SetCurrentCpuTact(69888 * i);
                beeperDevice.OnFrameCompleted();
                beeperDevice.AudioSamples.Length.ShouldBe(lenghts[i - 1]);
                beeperDevice.OnNewFrame();
            }
        }
        public void OnNewFrameInitsNextFrame()
        {
            // --- Arrange
            var spectrum     = new SpectrumBeepTestMachine();
            var beeperDevice = new BeeperDevice();

            beeperDevice.OnAttachedToVm(spectrum);

            // --- Act
            beeperDevice.OnNewFrame();

            // --- Assert
            beeperDevice.FrameCount.ShouldBe(1);
            beeperDevice.Pulses.Count.ShouldBe(0);
            beeperDevice.LastEarBit.ShouldBeTrue();
            beeperDevice.LastPulseTact.ShouldBe(0);
        }
        public void OnNewFrameKeepsLastEarBitValue()
        {
            // --- Arrange
            var spectrum     = new SpectrumBeepTestMachine();
            var beeperDevice = new BeeperDevice();

            beeperDevice.OnAttachedToVm(spectrum);

            // --- Act
            spectrum.SetCurrentFrameTact(100);
            beeperDevice.ProcessEarBitValue(false, false);
            spectrum.SetCurrentFrameTact(spectrum.FrameTacts);
            beeperDevice.OnFrameCompleted();
            beeperDevice.OnNewFrame();

            // --- Assert
            beeperDevice.FrameCount.ShouldBe(1);
            beeperDevice.Pulses.Count.ShouldBe(0);
            beeperDevice.LastEarBit.ShouldBeFalse();
            beeperDevice.LastPulseTact.ShouldBe(0);
        }