public void SwapTest()
        {

            // Arrange
            TileService service = new TileService();
            ITile tile3 = new Model.Fakes.StubITile { NumberGet = () => 3 };
            ITile tile7 = new Model.Fakes.StubITile { NumberGet = () => 7 };
            List<ITile> tiles = new List<ITile> {
                new Model.Fakes.StubITile { NumberGet =() => 1 },
                new Model.Fakes.StubITile { NumberGet =() => 2 },
                tile3,
                new Model.Fakes.StubITile { NumberGet =() => 4 },
                new Model.Fakes.StubITile { NumberGet =() => 5 },
                new Model.Fakes.StubITile { NumberGet =() => 6 },
                tile7,
                new Model.Fakes.StubITile { NumberGet =() => 8 },
                new Model.Fakes.StubITile { NumberGet =() => 9 },
            };
            int tile3Pos = tiles.IndexOf(tile3);
            int tile7Pos = tiles.IndexOf(tile7);

            // Act
            service.Swap(tiles, tile3, tile7);

            // Assert
            Assert.IsTrue(tiles[tile7Pos] == tile3);
            Assert.IsTrue(tiles[tile3Pos] == tile7);
        }
        public void If_I_Try_To_Swap_Only_Two_Letters()
        {
            IList<char> letters = new List<char> { 'z', 'h', };
            letters.Swap<char>(0, 1);

            Assert.IsTrue(letters.IndexOf('z') == 1);
            Assert.IsTrue(letters.IndexOf('h') == 0);
        }
 public void TestStringValueAttributeGetAll()
 {
     TestClass2 item = new TestClass2(7, "test", 0);
     string[] values = StringValueAttribute.GetAll(() => item.Id);
     Assert.IsNotNull(values);
     List<string> list = new List<string>(values);
     Assert.IsTrue(list.IndexOf("IdTest1") >= 0);
     Assert.IsTrue(list.IndexOf("IdTest2") >= 0);
     Assert.IsTrue(list.IndexOf("IdTest3") >= 0);
 }
Example #4
0
 public void TestAttributeUtilGetAllAsString()
 {
     TestClass2 item = new TestClass2(7, "test", 0);
     string[] values = AttributeUtil.GetAllAsString(() => item.Id, typeof(StringValueAttribute), "Value");
     Assert.IsNotNull(values);
     Assert.AreEqual(3, values.Length);
     List<string> list = new List<string>(values);
     Assert.IsTrue(list.IndexOf("IdTest1") >= 0);
     Assert.IsTrue(list.IndexOf("IdTest2") >= 0);
     Assert.IsTrue(list.IndexOf("IdTest3") >= 0);
 }
Example #5
0
 public void TestAttributeUtilGetAll()
 {
     TestClass2 item = new TestClass2(7, "test", 0);
     object[] objvalues = AttributeUtil.GetAll(() => item.Id, typeof(StringValueAttribute), "Value");
     Assert.IsNotNull(objvalues);
     List<string> values = new List<string>();
     foreach (object obj in objvalues)
     {
         values.Add((string)obj);
     }
     Assert.IsTrue(values.IndexOf("IdTest1") >= 0);
     Assert.IsTrue(values.IndexOf("IdTest2") >= 0);
     Assert.IsTrue(values.IndexOf("IdTest3") >= 0);
 }
Example #6
0
 // for debug
 public string PrintPath(int[,] grid, List<Point> path)
 {
     var sb = new StringBuilder();
     for (int y = 0; y < grid.GetLength(1); y++)
     {
         for (int x = 0; x < grid.GetLength(0); x++)
         {
             if (path.Contains(new Point(x, y)))
             {
                 var symbol = (path.IndexOf(new Point(x, y)) + 1) % 10;
                 sb.Append(symbol);
             }
             else if (grid[x, y] != 0)
             {
                 sb.Append('#');
             }
             else
             {
                 sb.Append('-');
             }
         }
         sb.AppendLine();
     }
     return sb.ToString();
 }
Example #7
0
 public void DoubleListTest()
 {
     var list = new List<double>();
     list.Add(10.1213131);
     list.Add(-4315.41412);
     Assert.IsFalse(list.Contains(10));
     Assert.AreEqual(10.1213131, list.GetElement(1));
     Assert.AreEqual(0, list.IndexOf(-4315.41412));
 }
Example #8
0
        public void NeutralLossListTest()
        {
            TestSmallMolecules = false; // No concept of neutral loss for small molecules

            var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3",
                LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), });

            SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangePeptideModifications(mods =>
                mods.ChangeStaticModifications(new List<StaticMod>(mods.StaticModifications) { phosphoLossMod })));
            IdentityPath path = IdentityPath.ROOT;
            SrmDocument docFasta = document.ImportFasta(new StringReader(TEXT_FASTA_YEAST_7), false, path, out path);

            Assert.AreEqual(0, GetLossCount(docFasta, 1));

            // Insert losses into the first transition group
            var pathPeptide = docFasta.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var nodePep = (PeptideDocNode) docFasta.FindNode(pathPeptide);
            var nodeGroup = (TransitionGroupDocNode) nodePep.Children[0];
            var listChildren = new List<DocNode>(nodeGroup.Children);
            foreach (var nodeTran in nodeGroup.GetTransitions(docFasta.Settings,
                nodePep.ExplicitMods, nodeGroup.PrecursorMz, null, null, null, false))
            {
                if (!nodeTran.HasLoss)
                    continue;

                var tran = nodeTran.Transition;
                int matchIndex = listChildren.IndexOf(node =>
                    Equals(tran, ((TransitionDocNode)node).Transition));
                if (matchIndex == -1)
                    continue;

                while (matchIndex < listChildren.Count &&
                    Equals(tran, ((TransitionDocNode)listChildren[matchIndex]).Transition))
                {
                    matchIndex++;
                }
                listChildren.Insert(matchIndex, nodeTran);
            }

            var docLosses = (SrmDocument) docFasta.ReplaceChild(pathPeptide,
                nodeGroup.ChangeChildren(listChildren));

            int lossCount = GetLossCount(docLosses, 1);
            Assert.IsTrue(lossCount > 0);
            var docRoundTripped = AssertEx.RoundTripTransitionList(new ThermoMassListExporter(docLosses));
            Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
            docRoundTripped = AssertEx.RoundTripTransitionList(new AgilentMassListExporter(docLosses));
            Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
        }
Example #9
0
		public void Sort_TwoDescription_ActualProperties ()
		{
			List<Rectangle> rects = new List<Rectangle> {
				new Rectangle { Width = 10, Height = 10 },
				new Rectangle { Width = 10, Height = 20 },
				new Rectangle { Width = 20, Height = 10 },
				new Rectangle { Width = 20, Height = 20 }
			};

			using (Source.DeferRefresh ()) {
				Source.Source = rects;
				Source.GroupDescriptions.Add (new ConcretePropertyGroupDescription {
					GroupNameFromItemFunc = (item, level, culture) => rects.IndexOf ((Rectangle)item) < 2 ? "A" : "B"
				});

				Source.SortDescriptions.Add (new SortDescription ("Width", ListSortDirection.Descending));
				Source.SortDescriptions.Add (new SortDescription ("Height", ListSortDirection.Ascending));
			}

			// Check the first group
			var group = (CollectionViewGroup) Source.View.Groups [0];
			Assert.AreSame (rects [2], group.Items [0], "#1");
			Assert.AreSame (rects [3], group.Items [1], "#2");
			
			// Check the second group
			group = (CollectionViewGroup) Source.View.Groups [1];
			Assert.AreSame (rects [0], group.Items [0], "#3");
			Assert.AreSame (rects [1], group.Items [1], "#4");
		}
Example #10
0
		public void Group_IndexOf()
		{
			List<Rectangle> rects = new List<Rectangle> {
				new Rectangle { Width = 10, Height = 10 },
				new Rectangle { Width = 10, Height = 20 },
				new Rectangle { Width = 20, Height = 10 },
				new Rectangle { Width = 20, Height = 20 }
			};

			SetSource(rects);
			using (Source.DeferRefresh ()) {
				Source.GroupDescriptions.Add (new ConcretePropertyGroupDescription {
					GroupNameFromItemFunc = (item, level, culture) => rects.IndexOf ((Rectangle)item) < 2 ? "A" : "B"
				});

				Source.SortDescriptions.Add (new SortDescription ("Width", ListSortDirection.Descending));
				Source.SortDescriptions.Add (new SortDescription ("Height", ListSortDirection.Ascending));
			}

			Assert.AreSame (rects [2], View.Cast<object>().ElementAt(0),  "#1");
			Assert.AreSame(rects[3], View.Cast<object>().ElementAt(1), "#2");
			Assert.AreSame(rects[0], View.Cast<object>().ElementAt(2), "#3");
			Assert.AreSame(rects[1], View.Cast<object>().ElementAt(3), "#4");
		}
        public void IndexOf()
        {
            List<int> stuff = new List<int>();
            stuff.AddRange(5, 6, 7, 8);

            int index = stuff.IndexOf((n) => n > 6);
            Assert.AreEqual(2, index);

            index = stuff.IndexOf((n) => n > 100);
            Assert.AreEqual(-1, index);
        }
Example #12
0
        public void IndexOf_IndexOfElementNotIncludedInCollection_IsProperlyObtained()
        {
            var list = new List<int>();
            for (var i = 0; i < 10; i++)
                list.Add(i);

            Assert.AreEqual(-1, list.IndexOf(34));
        }
Example #13
0
        public void IndexOf_ElementIsProperlyObtainedByIndex()
        {
            var list = new List<int>();
            for (var i = 0; i < 10; i++)
                list.Add(i);

            Assert.AreEqual(5, list.IndexOf(5));
        }
Example #14
0
 private bool CompareHookLists(List<Hook> expected, List<Hook> actual)
 {
     return
         expected == actual ||
         (expected.Count == actual.Count &&
         expected.TrueForAll(e => CompareHooks(e, actual[expected.IndexOf(e)])));
 }
 private void AssertTopologicallySorted(
     Dictionary<string, List<string>> graph,
     List<string> sortedNodes)
 {
     foreach (var node in graph)
     {
         foreach (var childNode in node.Value)
         {
             int nodeIndex = sortedNodes.IndexOf(node.Key);
             int childIndex = sortedNodes.IndexOf(childNode);
             Assert.IsTrue(
                 nodeIndex != -1,
                 "Node " + node.Key + " not found.");
             Assert.IsTrue(
                 childIndex != -1,
                 "Node " + childNode + " not found.");
             Assert.IsTrue(
                 nodeIndex < childIndex,
                 "Node " + node.Key + " should come before " + childNode);
         }
     }
 }
Example #16
0
        public void TestRemoveDuplicates2()
        {
            // Directed graph, a few duplicates.

            InitializeGraph(GraphDirectedness.Directed);

            IVertex[] aoVertices = AddVertices(4);

            for (Int32 i = 0; i < aoVertices.Length; i++)
            {
            aoVertices[i].Name = i.ToString(CultureInfo.InvariantCulture);
            }

            m_oEdgeCollection.Add(aoVertices[0], aoVertices[1], true);
            m_oEdgeCollection.Add(aoVertices[0], aoVertices[1], true);
            m_oEdgeCollection.Add(aoVertices[2], aoVertices[3], true);
            m_oEdgeCollection.Add(aoVertices[1], aoVertices[0], true);
            m_oEdgeCollection.Add(aoVertices[0], aoVertices[1], true);

            m_oEdgeCollection.RemoveDuplicates();

            List<String> oExpectedVertexIDPairs = new List<String>( new String[] {
            "0-1",
            "2-3",
            "1-0",
            } );

            Assert.AreEqual(oExpectedVertexIDPairs.Count, m_oEdgeCollection.Count);

            foreach (IEdge oEdge in m_oEdgeCollection)
            {
            String sVertex1Name = oEdge.Vertices[0].Name;
            String sVertex2Name = oEdge.Vertices[1].Name;

            Int32 iIndex = oExpectedVertexIDPairs.IndexOf(
                sVertex1Name + "-" + sVertex2Name
                );

            Assert.IsTrue(iIndex >= 0);

            oExpectedVertexIDPairs.RemoveAt(iIndex);
            }

            Assert.AreEqual(0, oExpectedVertexIDPairs.Count);
        }
Example #17
0
 public void TestIndexOf_LastValue_ReturnsZero()
 {
     var list = new List<int>() { 0, 1, 2 }.Reversed();
     int index = list.IndexOf(2);
     Assert.AreEqual(0, index);
 }
Example #18
0
 public void TestIndexOf_FirstValue_ReturnsCountMinusOne()
 {
     var list = new List<int>() { 0, 1, 2 }.Reversed();
     int index = list.IndexOf(0);
     Assert.AreEqual(list.Count - 1, index);
 }
Example #19
0
 public void TestIndexOf_LastValue_ReturnsZero()
 {
     var list = new List<int>() { 0, 1, 2 }.ReadOnly();
     int index = list.IndexOf(2);
     Assert.AreEqual(list.Count - 1, index);
 }
 public void GetRecsForReportTest()
 {
     EmployeeTableController target = new EmployeeTableController();
     DateTime start = new DateTime(today.Year, today.Month, today.Day - 2);
     DateTime end = new DateTime(today.Year, today.Month, today.Day - 1);
     List<Dictionary<string, object>> expected = new List<Dictionary<string, object>>();
     expected.Add(target.GetRecord(empId, start));
     expected.Add(target.GetRecord(empId, end));
     List<Dictionary<string, object>> actual;
     actual = target.GetRecsForReport(start, end);
     Assert.AreEqual(actual.Count, expected.Count);
     foreach (Dictionary<string, object> rec in expected)
     {
         Assert.IsTrue(recordCompare(rec, actual[expected.IndexOf(rec)]));
     }
 }
        private bool CompareTileLists(List<Tile> list1, List<Tile> list2)
        {
            bool areEqual = true;

            if (list1.Count != list2.Count)
            {
                return false;
            }

            foreach (Tile item in list1)
            {
                Tile tile1 = item;
                Tile tile2 = list2.ElementAt(list1.IndexOf(item));

                if (0 != tile1.CompareTo(tile2))
                {
                    areEqual = false;
                }

                if (!tile1.Label.Equals(tile2.Label))
                {
                    areEqual = false;
                }
            }

            return areEqual;
        }
        public void If_I_Try_To_Swap_Two_Items_By_Position_Having_Other_Letters_In_Collection()
        {
            IList<char> letters = new List<char> { 'a', 'z', 'h', 'd', };
            letters.Swap<char>(1, 3);

            Assert.IsTrue(letters.IndexOf('z') == 3);
            Assert.IsTrue(letters.IndexOf('d') == 1);
        }
Example #23
0
 public void TestIndexOf_MiddleValue_ReturnsExpectedIndex()
 {
     var list = new List<int>() { 0, 1, 2, 3 }.Reversed();
     int index = list.IndexOf(1);
     Assert.AreEqual(2, index);
 }
 public void GetStudentReportTest()
 {
     VisitorTableController target = new VisitorTableController(); // TODO: Initialize to an appropriate value
     DateTime start = new DateTime(today.Year, today.Month, today.Day - 2);
     DateTime end = new DateTime(today.Year, today.Month, today.Day - 1);
     List<Dictionary<string, object>> expected = new List<Dictionary<string, object>>();
     expected.Add(target.GetRecordWithStudents(visId, start));
     expected.Add(target.GetRecordWithStudents(visId, end));
     List<Dictionary<string, object>> actual;
     actual = target.GetStudentReport(start, end);
     Assert.AreEqual(actual.Count, expected.Count);
     foreach (Dictionary<string, object> rec in expected)
     {
         Assert.IsTrue(recordCompare(rec, actual[expected.IndexOf(rec)]));
     }
 }
Example #25
0
 public void TestAttributeUtilGetCustomAttributes()
 {
     TestClass2 item = new TestClass2(7, "test", 0);
     StringValueAttribute[] attributes = (StringValueAttribute[])AttributeUtil.GetCustomAttributes(() => item.Id, typeof(StringValueAttribute));
     Assert.IsNotNull(attributes);
     Assert.AreEqual(3, attributes.Length);
     List<string> values = new List<string>();
     values.Add(attributes[0].Value);
     values.Add(attributes[1].Value);
     values.Add(attributes[2].Value);
     Assert.IsTrue(values.IndexOf("IdTest1") >= 0);
     Assert.IsTrue(values.IndexOf("IdTest2") >= 0);
     Assert.IsTrue(values.IndexOf("IdTest3") >= 0);
 }
Example #26
0
 public void TestIndexOf_MultipleOccurrences_ReturnsLastIndex()
 {
     var list = new List<int>() { 0, 1, 0, 1 }.Reversed();
     int index = list.IndexOf(0);
     Assert.AreEqual(1, index);
 }
Example #27
0
        public void TestRemoveDuplicates6()
        {
            // Undirected graph, many duplicates.

            InitializeGraph(GraphDirectedness.Undirected);

            IVertex[] aoVertices = AddVertices(10000);

            for (Int32 i = 0; i < aoVertices.Length; i++)
            {
            aoVertices[i].Name = i.ToString(CultureInfo.InvariantCulture);
            }

            for (Int32 i = 0; i < 10000; i++)
            {
            m_oEdgeCollection.Add(aoVertices[0], aoVertices[1], false);
            m_oEdgeCollection.Add(aoVertices[2], aoVertices[3], false);
            m_oEdgeCollection.Add(aoVertices[3], aoVertices[4], false);

            m_oEdgeCollection.Add(aoVertices[1], aoVertices[0], false);
            m_oEdgeCollection.Add(aoVertices[3], aoVertices[2], false);
            m_oEdgeCollection.Add(aoVertices[4], aoVertices[3], false);
            }

            m_oEdgeCollection.Add(aoVertices[5], aoVertices[6], false);

            m_oEdgeCollection.RemoveDuplicates();

            List<String> oExpectedVertexIDPairs = new List<String>( new String[] {
            "0-1",
            "2-3",
            "3-4",
            "5-6",
            } );

            Assert.AreEqual(oExpectedVertexIDPairs.Count, m_oEdgeCollection.Count);

            foreach (IEdge oEdge in m_oEdgeCollection)
            {
            String sVertex1Name = oEdge.Vertices[0].Name;
            String sVertex2Name = oEdge.Vertices[1].Name;

            String sVertexIDPair = (sVertex1Name.CompareTo(sVertex2Name) < 0) ?
                sVertex1Name + "-" + sVertex2Name
                :
                sVertex2Name + "-" + sVertex1Name
                ;

            Int32 iIndex = oExpectedVertexIDPairs.IndexOf(sVertexIDPair);

            Assert.IsTrue(iIndex >= 0);

            oExpectedVertexIDPairs.RemoveAt(iIndex);
            }

            Assert.AreEqual(0, oExpectedVertexIDPairs.Count);
        }
Example #28
0
 public void TestIndexOf_ValueNotFound_ReturnsNegativeOne()
 {
     var list = new List<int>() { 0, 1, 2 }.Reversed();
     int index = list.IndexOf(3);
     Assert.AreEqual(-1, index);
 }
 public void CanSolveForest()
 {
     solver.AddModule("ModuleA");
     solver.AddModule("ModuleB");
     solver.AddModule("ModuleC");
     solver.AddModule("ModuleD");
     solver.AddModule("ModuleE");
     solver.AddModule("ModuleF");
     solver.AddDependency("ModuleC", "ModuleB");
     solver.AddDependency("ModuleB", "ModuleA");
     solver.AddDependency("ModuleE", "ModuleD");
     string[] result = solver.Solve();
     Assert.AreEqual(6, result.Length);
     List<string> test = new List<string>(result);
     Assert.IsTrue(test.IndexOf("ModuleA") < test.IndexOf("ModuleB"));
     Assert.IsTrue(test.IndexOf("ModuleB") < test.IndexOf("ModuleC"));
     Assert.IsTrue(test.IndexOf("ModuleD") < test.IndexOf("ModuleE"));
 }
Example #30
0
 public void TestBaseIndex_IndexInMiddle_ReturnsUnderlyingIndex()
 {
     var list = new List<int>() { 1, 2, 3, 4 }.Reversed();
     Assert.AreEqual(list.List.IndexOf(3), list.BaseIndex(list.IndexOf(3)), "The wrong index was returned.");
 }