public void SimpleEnumerationTestWithLinqOperator()
		{
			MultiValueDictionary<int, string> container = new MultiValueDictionary<int, string> { { 1, "value1" }, { 2, "value2" }, { 2, "value3" } };

			foreach(KeyValuePair<int, HashSet<string>> pair in container.OrderBy(p=>p.Key))
			{
				switch(pair.Key)
				{
					case 1:
						Assert.AreEqual("value1", pair.Value.First());
						break;
					case 2:
						Assert.AreEqual(2, pair.Value.Count);
						Assert.IsTrue(pair.Value.Contains("value2"));
						Assert.IsTrue(pair.Value.Contains("value3"));
						break;
				}
			}
		}
        public void SimpleEnumerationTestWithLinqOperator()
        {
            MultiValueDictionary <int, string> container = new MultiValueDictionary <int, string> {
                { 1, "value1" }, { 2, "value2" }, { 2, "value3" }
            };

            foreach (KeyValuePair <int, HashSet <string> > pair in container.OrderBy(p => p.Key))
            {
                switch (pair.Key)
                {
                case 1:
                    Assert.AreEqual("value1", pair.Value.First());
                    break;

                case 2:
                    Assert.AreEqual(2, pair.Value.Count);
                    Assert.IsTrue(pair.Value.Contains("value2"));
                    Assert.IsTrue(pair.Value.Contains("value3"));
                    break;
                }
            }
        }
Esempio n. 3
0
        public static ICollection <AnnotatedTransaction> TopologicalSort(this ICollection <AnnotatedTransaction> transactions)
        {
            var confirmed   = new MultiValueDictionary <int, AnnotatedTransaction>();
            var unconfirmed = new List <AnnotatedTransaction>();
            var result      = new List <AnnotatedTransaction>(transactions.Count);

            foreach (var tx in transactions)
            {
                if (tx.Height is int h)
                {
                    confirmed.Add(h, tx);
                }
                else
                {
                    unconfirmed.Add(tx);
                }
            }
            foreach (var tx in confirmed.OrderBy(o => o.Key))
            {
                if (tx.Value.Count == 1)
                {
                    result.Add(tx.Value.First());
                }
                else
                {
                    foreach (var tx2 in tx.Value.TopologicalSortCore())
                    {
                        result.Add(tx2);
                    }
                }
            }
            foreach (var tx in unconfirmed.TopologicalSortCore())
            {
                result.Add(tx);
            }
            return(result);
        }