public void EqualsTest()
        {
            var a = TileData.Create("A");
            var b = TileData.Create("B");

            var sequences = new[]
            {
                TileSequence.FromData(),
                TileSequence.FromData(a, a),
                TileSequence.FromData(a, b),
                TileSequence.FromData(b, a)
            };

            for (var i = 0; i < sequences.Length; i++)
            {
                for (var j = 0; j < sequences.Length; j++)
                {
                    var lhs = sequences[i];
                    var rhs = sequences[j];

                    var equals  = lhs.Equals(rhs);
                    var lhsHash = lhs.GetHashCode();
                    var rhsHash = rhs.GetHashCode();

                    Assert.AreEqual(i == j, equals);
                    Assert.IsTrue(!equals || lhsHash == rhsHash);

                    var equalsUntyped   = lhs.Equals((object)rhs);
                    var unequalsUntyped = lhs.Equals(42);
                    Assert.AreEqual(equals, equalsUntyped);
                    Assert.IsFalse(unequalsUntyped);
                }
            }

            Assert.AreNotEqual(sequences[0], "Ethel the Aardvark");
        }
        public void ComplexishConstructionTest()
        {
            var sequence = TileSequence.FromData(TileData.Create("hello"), TileData.Create("world"));

            Assert.IsNotNull(sequence);
        }
        private static void SequenceSanityCheck(params TileData[] tiles)
        {
            var sequence = TileSequence.FromData(tiles);

            SequenceSanityCheck(sequence);
        }
        public void SimpleConstructionTest()
        {
            var sequence = TileSequence.FromData();

            Assert.IsNotNull(sequence);
        }
Esempio n. 5
0
        internal void Commit(ITile stopTile)
        {
            ParanoidAssertValid();

            // Find position from which to work backwards to rebirth ghost items.
            ITile position;

            if (_selectedIndex == 0 &&
                stopTile is GhostStopItem)
            {
                position = _headItems[_headItems.Count - 1].Predecessor;
            }
            else
            {
                position = stopTile.Predecessor;
            }

            var wordList = new List <string>();

            while (!ReferenceEquals(LastTile, position))
            {
                wordList.Insert(0, position.Content);
                position = position.Predecessor;
            }

            AddWords(wordList);

            if (_selectedIndex == 0 &&
                2 < _headItems.Count &&
                _headItems[_headItems.Count - 1] is GhostStopItem)
            {
                TransferRunOnToSuccessors(_headItems[_headItems.Count - 2]);
            }

            ParanoidAssertValid();

            var selection = new List <int>(Context)
            {
                0
            };

            RollbackAndAddSequence(selection, PersistedSequenceWeight);

            var predecessor = _headItems[0];

            for (var i = 1; i <= _selectedIndex; i++)
            {
                var selected = _headItems[i];
                var ghost    = CreateGhostWordItem(predecessor, selected.Content);
                _headItems[i] = ghost;
                predecessor   = ghost;
            }

            while (_selectedIndex + 1 < _headItems.Count)
            {
                _headItems.RemoveAt(_headItems.Count - 1);
            }

            selection.RemoveAt(0);
            selection.RemoveAt(selection.Count - 1);
            var tiles = new List <TileData>();

            foreach (var token in selection)
            {
                var tokenString = _tokens.GetString(token);
                var tile        = TileData.FromTokenString(tokenString);
                tiles.Add(tile);
            }
            var utterance = TileSequence.FromData(tiles);

            SetSelectedIndex(0);
            var tail = new GhostStopItem(predecessor, this);

            _headItems.Add(tail);

            Model.SaveUtterance(utterance);

            InitializeUtterance();
            SetSuggestionsViewComplete();

            ParanoidAssertValid();
        }