public void MarkovLink_IsPrefix_CorrectPrefix_ReturnTrue()
        {
            var r = new Random();
            var chain = new MarkovLink<string>(r);

            var prefix = new[] {"one", "two"};

            chain.Prefixes = new List<string>(prefix);

            CollectionAssert.AreEqual(prefix, chain.Prefixes);

            Assert.IsTrue(chain.IsPrefix(prefix));
        }
        public void MarkovLink_IsPrefix_IncorrectPrefix_ReturnFalse()
        {
            var r = new Random();
            var chain = new MarkovLink<string>(r);

            var prefix = new[] {"one", "two"};

            chain.Prefixes = new List<string>(prefix);

            var differentPrefix = new[] {"two", "three"};

            var outOfOrderPrefix = new[] {"two", "one"};

            Assert.IsFalse(chain.IsPrefix(differentPrefix));
            Assert.IsFalse(chain.IsPrefix(outOfOrderPrefix));
        }
示例#3
0
 private MarkovLink<char> GetLink(MarkovLink<char> key)
 {
     if (_links.ContainsKey(key.GetHashCode()))
         return _links[key.GetHashCode()];
     else
         return null;
 }
示例#4
0
        private void AddLink(char[] bitOfIndex)
        {
            var link = new MarkovLink<char>(_r);
            link.Prefixes.AddRange(bitOfIndex.Take(LettersToKeep - 1));
            link.AddSuffix(bitOfIndex.Last());

            var targetLink = GetLink(link);

            if (targetLink == null)
            {
                _links.Add(link.GetHashCode(), link);
            }
            else
            {
                targetLink.AddSuffixFromLink(link);
            }
        }