示例#1
0
        public void BlockEnumerator_Next_WithInputShorterThatBlockSize_ReturnsFalse()
        {
            var enumerator = new BlockEnumerator <int>(new int[] { 1, 2, 3 }, 4);

            bool result = enumerator.Next();

            Assert.That(result, Is.False);
        }
示例#2
0
        public void BlockEnumerator_Next_WithEmptyInput_ReturnsFalse()
        {
            var enumerator = new BlockEnumerator <int>(new int[0], 1);

            bool result = enumerator.Next();

            Assert.That(result, Is.False);
        }
示例#3
0
                    public IEnumerator <KeyValuePair <string, long> > GetEnumerator()
                    {
                        if (m_enumerator != null)
                        {
                            throw new NotSupportedException("Cannot read block stream twice");
                        }

                        return(m_enumerator = new BlockEnumerator(m_compression, m_filename));
                    }
示例#4
0
                    public KeyValuePair <string, long> ReadVolumeProps()
                    {
                        if (m_enumerator == null)
                        {
                            m_enumerator = (BlockEnumerator)this.GetEnumerator();
                        }

                        return(m_enumerator.ReadVolumeProps());
                    }
示例#5
0
        public void Learn(IEnumerable <T> seq)
        {
            Guard.NotNull(seq, nameof(seq));

            var enumerator = new BlockEnumerator <T>(seq, 2);

            while (enumerator.Next())
            {
                T first  = enumerator.CurrentBlock[0];
                T second = enumerator.CurrentBlock[1];

                _states[first].Links[_states[second]] += 1;
            }
        }
        public void Learn(IEnumerable <T> seq)
        {
            Guard.NotNull(seq, nameof(seq));

            var enumerator = new BlockEnumerator <T>(seq, _order + 1);

            while (enumerator.Next())
            {
                T[] first  = enumerator.CurrentBlock.Take(_order).ToArray();
                T[] second = enumerator.CurrentBlock.Skip(1).Take(_order).ToArray();

#warning Storing the last item of the key in the MArkov state may not be appropriate for order > 1
                _states[first].Links[_states[second]] += 1;
            }
        }
示例#7
0
        public void BlockEnumerator_Next_WithInputLongerThatBlockSize_EnumeratesByBlock()
        {
            var enumerator = new BlockEnumerator <int>(new[] { 1, 2, 3, 4, 5 }, 2);


            Assert.That(enumerator.Next(), Is.True);
            Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 1, 2 }));

            Assert.That(enumerator.Next(), Is.True);
            Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 2, 3 }));

            Assert.That(enumerator.Next(), Is.True);
            Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 3, 4 }));

            Assert.That(enumerator.Next(), Is.True);
            Assert.That(enumerator.CurrentBlock, Is.EquivalentTo(new[] { 4, 5 }));

            Assert.That(enumerator.Next(), Is.False);
            Assert.That(enumerator.CurrentBlock, Is.Null);
        }