public void GetUnlinkedValues_InUnlinkedState_CorrectUnlinkedValue() { var tileOne = new DominoTileEntity(2, 1); Assert.Equal(2, tileOne.GetUnlinkedValues().Count()); Assert.True(tileOne.GetUnlinkedValues().Any(v => v == 1)); Assert.True(tileOne.GetUnlinkedValues().Any(v => v == 2)); }
public void Link_EngineWithMatching_CorrectLink() { var engine = new DominoTileEntity(12, 12, true); var tile = new DominoTileEntity(12, 11); tile.Link(engine); Assert.Equal(engine, tile.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tile.GetStateType().Name); Assert.Equal(1, tile.GetUnlinkedValues().Count()); Assert.Equal(11, tile.GetUnlinkedValues().First()); }
public void Link_OnAlreadyLinkedValue_ThrowsException() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); var tileThree = new DominoTileEntity(2, 4); tileOne.Link(tileTwo); Action linkThreeOnTwo = () => tileTwo.Link(tileThree); Action linkTwoOnThree = () => tileThree.Link(tileTwo); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(3, tileTwo.GetUnlinkedValues().First()); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.ThrowsAny <Exception>(linkThreeOnTwo); Assert.ThrowsAny <Exception>(linkTwoOnThree); }
public void Link_ThreeTiles_LinkedRefsAreCorrect() { var engine = new DominoTileEntity(12, 12, true); var tileOne = new DominoTileEntity(12, 11); var tileTwo = new DominoTileEntity(11, 10); tileOne.Link(engine); tileTwo.Link(tileOne); Assert.True(tileOne.IsLinked(engine)); Assert.True(tileTwo.IsLinked(tileOne)); Assert.Equal("FullyLinkedState", tileOne.GetStateType().Name); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(10, tileTwo.GetUnlinkedValues().First()); }
public void ForceAddTile(DominoTileEntity tile) { if (head == null && tail == null) { head = tail = tile; return; } if (head == tail && tile.GetUnlinkedValues().Any(x => x == head.FirstValue)) { tile.Link(head); tail = tile; return; } if (head.MatchesUnlinkedValue(tile)) { tile.Link(head); head = tile; return; } if (tail.MatchesUnlinkedValue(tile)) { tail.Link(tile); tail = tile; return; } throw new ApplicationException($"Illegal move. Head nor tail matches '{tile}'"); }
public void Link_TwoMatching_CorrectLink() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); tileTwo.Link(tileOne); Assert.Equal(tileOne, tileTwo.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tileTwo.GetStateType().Name); Assert.Equal(1, tileTwo.GetUnlinkedValues().Count()); Assert.Equal(3, tileTwo.GetUnlinkedValues().First()); Assert.Equal(tileTwo, tileOne.GetLinkedTiles().First()); Assert.Equal("HalfLinkedState", tileOne.GetStateType().Name); Assert.Equal(1, tileOne.GetUnlinkedValues().Count()); Assert.Equal(1, tileOne.GetUnlinkedValues().First()); }
public void Link_TilesOnEachSide_NoUnlinkedValues() { var tileOne = new DominoTileEntity(1, 2); var tileTwo = new DominoTileEntity(2, 3); var tileThree = new DominoTileEntity(1, 4); tileOne.Link(tileTwo); tileOne.Link(tileThree); Assert.Equal(0, tileOne.GetUnlinkedValues().Count()); }