public void CopyToTest()
 {
     for (int y = 1900; y < 2123; y++) {
         var values = CreateZmanim(y);
         var array = new KeyValuePair<DateTime, ZmanimInfo>[values.Length + 33];
         new YearlyZmanimDictionary(y, values).CopyTo(array, 33);
         Assert.IsTrue(array.Skip(33).Select(kvp => kvp.Value).SequenceEqual(values));
         Assert.IsTrue(array.Skip(33).All(kvp => kvp.Key == kvp.Value.Date));
     }
 }
Example #2
0
        public void CopyToTest()
        {
            var dict = new ShieldedDict<int, object>(
                Enumerable.Range(1, 1000).Select(i =>
                    new KeyValuePair<int, object>(i, new object())).ToArray());
            Assert.AreEqual(1000, dict.Count);

            var array = new KeyValuePair<int, object>[1100];
            // this works out of transaction (and consequently, so do ToArray and ToList), by opening
            // a transaction itself. that could not be done when you do a foreach.
            ((ICollection<KeyValuePair<int, object>>)dict).CopyTo(array, 100);
            var keys = new HashSet<int>();
            foreach (var kvp in array.Skip(100))
            {
                Assert.IsTrue(dict.ContainsKey(kvp.Key));
                Assert.IsTrue(keys.Add(kvp.Key));
                Assert.AreEqual(dict[kvp.Key], kvp.Value);
            }
        }
Example #3
0
        public void CopyToTest()
        {
            var tree = new ShieldedTree<int, object>();
            ParallelEnumerable.Range(1, 1000).ForAll(
                i => Shield.InTransaction(() => tree.Add(i, new object())));
            Assert.AreEqual(1000, tree.Count);

            var array = new KeyValuePair<int, object>[1100];
            ((ICollection<KeyValuePair<int, object>>)tree).CopyTo(array, 100);
            var expected = 1;
            foreach (var kvp in array.Skip(100))
            {
                Assert.IsTrue(tree.ContainsKey(kvp.Key));
                Assert.AreEqual(expected, kvp.Key);
                Assert.AreEqual(tree[kvp.Key], kvp.Value);
                expected++;
            }
        }
Example #4
0
        public void CopyTo_IndexNonZero_ValuesCopied()
        {
            Trie<string, char, int> trie = new Trie<string, char, int>();

            trie.Add("key1", 5);
            trie.Add("key2", 6);

            KeyValuePair<string, int>[] vals = new KeyValuePair<string, int>[4];
            trie.CopyTo(vals, 2);

            Assert.AreEqual(0, vals[0].Value);
            Assert.AreEqual(0, vals[1].Value);
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key1" && k.Value == 5));
            Assert.IsTrue(vals.Skip(2).Any(k => k.Key == "key2" && k.Value == 6));
        }