public void ToLookupOfStringReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument a = new Document(engine, pipeline)
                .Clone("a", new[] { new KeyValuePair<string, object>("Numbers", new[] { 1, 2, 3 }) });
            IDocument b = new Document(engine, pipeline)
                .Clone("b", new[] { new KeyValuePair<string, object>("Numbers", new[] { 2, 3, 4 }) });
            IDocument c = new Document(engine, pipeline)
                .Clone("c", new[] { new KeyValuePair<string, object>("Numbers", 3) });
            IDocument d = new Document(engine, pipeline)
                .Clone("d", new[] { new KeyValuePair<string, object>("Numbers", "4") });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<string, IDocument> lookup = documents.ToLookup<string>("Numbers");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEquivalent(new[] { a }, lookup["1"]);
            CollectionAssert.AreEquivalent(new[] { a, b }, lookup["2"]);
            CollectionAssert.AreEquivalent(new[] { a, b, c }, lookup["3"]);
            CollectionAssert.AreEquivalent(new[] { b, d }, lookup["4"]);
        }
        public void ChangesToSourceSequenceAfterToLookupAreNotNoticed()
        {
            List<string> source = new List<string> { "abc" };
            var lookup = source.ToLookup(x => x.Length);
            Assert.AreEqual(1, lookup.Count);

            // Potential new key is ignored
            source.Add("x");
            Assert.AreEqual(1, lookup.Count);

            // Potential new value for existing key is ignored
            source.Add("xyz");
            lookup[3].AssertSequenceEqual("abc");
        }
            public void ReturnsCorrectLookupOfString()
            {
                // Given
                IDocument a = new Document(
                    new InitialMetadata { { "Numbers", new[] { 1, 2, 3 } } }, "a");
                IDocument b = new Document(
                    new InitialMetadata { { "Numbers", new[] { 2, 3, 4 } } }, "b");
                IDocument c = new Document(
                    new InitialMetadata { { "Numbers", 3 } }, "c");
                IDocument d = new Document(
                    new InitialMetadata { { "Numbers", "4" } }, "d");
                List<IDocument> documents = new List<IDocument>() { a, b, c, d };

                // When
                ILookup<string, IDocument> lookup = documents.ToLookup<string>("Numbers");

                // Then
                Assert.AreEqual(4, lookup.Count);
                CollectionAssert.AreEquivalent(new[] { a }, lookup["1"]);
                CollectionAssert.AreEquivalent(new[] { a, b }, lookup["2"]);
                CollectionAssert.AreEquivalent(new[] { a, b, c }, lookup["3"]);
                CollectionAssert.AreEquivalent(new[] { b, d }, lookup["4"]);
            }
        public void ToLookupOfIntReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            IDocument a = new Document(new Metadata(engine))
                .Clone("a", new[] { new KeyValuePair<string, object>("Numbers", new [] { 1, 2, 3 }) });
            IDocument b = new Document(new Metadata(engine))
                .Clone("b", new[] { new KeyValuePair<string, object>("Numbers", new [] { 2, 3, 4 }) });
            IDocument c = new Document(new Metadata(engine))
                .Clone("c", new[] { new KeyValuePair<string, object>("Numbers", 3) });
            IDocument d = new Document(new Metadata(engine))
                .Clone("d", new[] { new KeyValuePair<string, object>("Numbers", "4") });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<int, IDocument> lookup = documents.ToLookup<int>("Numbers");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEqual(new[] { a }, lookup[1]);
            CollectionAssert.AreEqual(new[] { a, b }, lookup[2]);
            CollectionAssert.AreEqual(new[] { a, b, c }, lookup[3]);
            CollectionAssert.AreEqual(new[] { b, d }, lookup[4]);
        }
        public void ToLookupWithValuesReturnsCorrectLookup()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument a = new Document(engine, pipeline)
                .Clone("a", new[]
                {
                    new KeyValuePair<string, object>("Numbers", new[] { 1, 2, 3 }),
                    new KeyValuePair<string, object>("Colors", "Red") 
                });
            IDocument b = new Document(engine, pipeline)
                .Clone("b", new[]
                {
                    new KeyValuePair<string, object>("Numbers", new[] { 2, 3, 4 }),
                    new KeyValuePair<string, object>("Colors", new [] { "Red", "Blue" })
                });
            IDocument c = new Document(engine, pipeline)
                .Clone("c", new[]
                {
                    new KeyValuePair<string, object>("Numbers", 3),
                    new KeyValuePair<string, object>("Colors", "Green")
                });
            IDocument d = new Document(engine, pipeline)
                .Clone("d", new[]
                {
                    new KeyValuePair<string, object>("Numbers", "4"),
                    new KeyValuePair<string, object>("Colors", new [] { "Green", "Blue" })
                });
            List<IDocument> documents = new List<IDocument>() { a, b, c, d };

            // When
            ILookup<int, string> lookup = documents.ToLookup<int, string>("Numbers", "Colors");

            // Then
            Assert.AreEqual(4, lookup.Count);
            CollectionAssert.AreEquivalent(new[] { "Red" }, lookup[1]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue" }, lookup[2]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[3]);
            CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[4]);
        }
Ejemplo n.º 6
0
 public void sampletest()
 {
     List<Person> s1 = new List<Person>();
     s1.Add(new Person(1, "oplok", "langit"));
     s1.Add(new Person(2, "oplo2k", "langit2"));
     List<Person> s2 = new List<Person>();
     s2.Add(new Person(1, "oplok", "langit3"));
     s2.Add(new Person(2, "loslos", "olympus2"));
     //List<Person> s3 = s1.Except(s2).ToList();
     var list2lookUp = s1.ToLookup(p => p.name);
     var listdiff = s2.Where(p => (!list2lookUp.Contains(p.name)));
     foreach(Person s in listdiff){
         Console.WriteLine(s.name + ": " + s.address);
     }
     Console.WriteLine("================================");
 }
Ejemplo n.º 7
0
        public void Investigate()
        {
            var connection = new OleDbConnection();
            var mdb = @"c:\users\dan\desktop\rettig.mdb";
            var x = IntPtr.Size;
            connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + mdb;
            connection.Open();

            var koppling = new List<Tuple<int, int>>();
            using (var dr = (new OleDbCommand("SELECT mfd10070_id,mfd10015_id FROM mfd10071", connection)).ExecuteReader())
                while (dr.Read())
                    koppling.Add(new Tuple<int, int>(dr.GetInt32(0), dr.GetInt32(1)));

            var radiatortyp = new List<Tuple<int, int>>();
            using (var dr = (new OleDbCommand("SELECT id, mfd10010_id from mfd10015", connection)).ExecuteReader())
                while (dr.Read())
                {
                    var typeId = dr.GetInt32(1);
                    if (typeId < 9 ) //&& typeId != 7)
                        continue;
                    radiatortyp.Add(new Tuple<int, int>(dr.GetInt32(0), typeId));
                }

            var rts = radiatortyp.ToLookup(_ => _.Item2, _ => _.Item1);
            foreach (var rt in rts)
            {
                var allLuftDonMapings = new Dictionary<int, List<int>>();
                foreach (var rId in rt)
                {
                    allLuftDonMapings[rId] = koppling.Where(_ => _.Item2 == rId).Select(_ => _.Item1).Distinct().ToList();
                    foreach(var val in allLuftDonMapings.Values)
                        val.Sort();
                    if (!allEqual(allLuftDonMapings.Values.ToList()))
                    {
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void GroupingEnumerator()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup<int, int>(ints.ToLookup(i => Int32.Parse(i.ToString()[0].ToString())));

            Assert.AreEqual (2, lookup[2].Count());
            Assert.IsTrue (lookup[2].Any (i => i == 20));
            Assert.IsTrue (lookup[2].Any(i => i == 21));
        }
Ejemplo n.º 9
0
        public void EnumeratorNotNull()
        {
            List<string> strings = new List<string> { "hi", "hai", "bai", "bye" };
            var lookup = new MutableLookup<string, string> (strings.ToLookup (s => s[0].ToString()));

            Assert.AreEqual (2, lookup.Count);
            Assert.IsTrue (lookup.Any (g => g.Key == "h"));
            Assert.IsTrue (lookup.Any (g => g.Key == "b"));
            Assert.IsFalse (lookup.Any (g => g.Key == null));
        }
Ejemplo n.º 10
0
        public void Enumerator()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup<int, int>(ints.ToLookup(i => Int32.Parse(i.ToString()[0].ToString())));

            Assert.AreEqual (3, lookup.Count());
            Assert.IsTrue (lookup.Any (g => g.Key == 1));
            Assert.IsTrue (lookup.Any (g => g.Key == 2));
            Assert.IsTrue (lookup.Any (g => g.Key == 3));
        }
Ejemplo n.º 11
0
        public void CtorILookupWithNulls()
        {
            List<string> strs = new List<string> { "Foo", "Foos", "Foobar", "Monkeys", "Bar", "Ban", "Barfoo" };

            var lookup = new MutableLookup<string, string> (strs.ToLookup (s => (s[0] != 'F' && s[0] != 'B') ? null : s[0].ToString()));
            Assert.AreEqual (3, lookup.Count);
            Assert.AreEqual (3, lookup["F"].Count());
            Assert.AreEqual (3, lookup["B"].Count());
            Assert.AreEqual (1, lookup[null].Count());
        }
Ejemplo n.º 12
0
        public void CtorILookup()
        {
            List<int> ints = new List<int> { 10, 20, 21, 30 };
            var lookup = new MutableLookup <int, int> (ints.ToLookup (i => Int32.Parse (i.ToString()[0].ToString())));

            Assert.AreEqual (3, lookup.Count);
            Assert.AreEqual (1, lookup[1].Count());
            Assert.AreEqual (2, lookup[2].Count());
            Assert.AreEqual (1, lookup[3].Count());
        }
            public void ReturnsCorrectLookupWithValues()
            {
                // Given
                IDocument a = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", new[] { 1, 2, 3 } },
                        { "Colors", "Red" }
                    }, "a");
                IDocument b = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", new[] { 2, 3, 4 } },
                        { "Colors", new [] { "Red", "Blue" } }
                    }, "b");
                IDocument c = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", 3 },
                        { "Colors", "Green" }
                    }, "c");
                IDocument d = new Document(
                    new InitialMetadata
                    {
                        { "Numbers", "4" },
                        { "Colors", new [] { "Green", "Blue" } }
                    }, "d");
                List<IDocument> documents = new List<IDocument>() { a, b, c, d };

                // When
                ILookup<int, string> lookup = documents.ToLookup<int, string>("Numbers", "Colors");

                // Then
                Assert.AreEqual(4, lookup.Count);
                CollectionAssert.AreEquivalent(new[] { "Red" }, lookup[1]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue" }, lookup[2]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[3]);
                CollectionAssert.AreEquivalent(new[] { "Red", "Blue", "Green" }, lookup[4]);
            }