Example #1
0
 public void TestAddingTreeElements()
 {
     TripleList<int> tripleList = new TripleList<int>();
     int value1 = 4;
     int value2 = -9;
     int value3 = 47;
     tripleList.Add(value1);
     tripleList.Add(value2);
     tripleList.Add(value3);
     Assert.AreEqual(3, tripleList.Count());
     // checking values
     Assert.AreEqual(value1, tripleList.Value);
     Assert.AreEqual(value2, tripleList.MiddleElement.Value);
     Assert.AreEqual(value3, tripleList.NextElement.Value);
     // checking neighbour Nodes of first element
     Assert.IsNull(tripleList.PreviousElement);
     Assert.IsNotNull(tripleList.MiddleElement);
     Assert.IsNotNull(tripleList.NextElement);
     // checking neighbour Nodes of second element
     Assert.IsNull(tripleList.MiddleElement.PreviousElement);
     Assert.IsNotNull(tripleList.MiddleElement.MiddleElement);
     Assert.IsNull(tripleList.MiddleElement.NextElement);
     // checking neighbour Nodes of third/last element
     Assert.IsNotNull(tripleList.NextElement.PreviousElement);
     Assert.IsNull(tripleList.NextElement.MiddleElement);
     Assert.IsNull(tripleList.NextElement.NextElement);
     // checking values
     Assert.AreEqual(value1, tripleList.Value);
     Assert.AreEqual(value2, tripleList.MiddleElement.Value);
     Assert.AreEqual(value3, tripleList.NextElement.Value);
 }
Example #2
0
        /// <summary>
        /// <para>Creates a CMSSolutions.Collections.Generic.TripleCollection&lt;TFirst,TSecond,TThird&gt; from a System.Collections.Generic.IEnumerable&lt;T&gt;</para>
        /// <para>according to specified first and second selector functions.</para>
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TFirst">The type of the First returned by firstSelector.</typeparam>
        /// <typeparam name="TSecond">The type of the Second returned by secondSelector.</typeparam>
        /// <typeparam name="TThird">The type of the Third returned by thirdSelector.</typeparam>
        /// <param name="source"></param>
        /// <param name="firstSelector">A transform function to produce a result element First from each element.</param>
        /// <param name="secondSelector">A transform function to produce a result element Second from each element.</param>
        /// <param name="thirdSelector">A transform function to produce a result element Third from each element.</param>
        /// <returns>
        /// <para>A CMSSolutions.Collections.Generic.TripleCollection&lt;TFirst,TSecond,TThird&gt; that contains values</para>
        /// <para> of type TFirst, TSecond and TThird selected from the input sequence.</para>
        /// </returns>
        public static TripleList <TFirst, TSecond, TThird> ToTripleList <TSource, TFirst, TSecond, TThird>(
            this IEnumerable <TSource> source,
            Func <TSource, TFirst> firstSelector,
            Func <TSource, TSecond> secondSelector,
            Func <TSource, TThird> thirdSelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (firstSelector == null)
            {
                throw new ArgumentNullException("firstSelector");
            }
            if (secondSelector == null)
            {
                throw new ArgumentNullException("secondSelector");
            }
            if (thirdSelector == null)
            {
                throw new ArgumentNullException("thirdSelector");
            }
            var dictionary = new TripleList <TFirst, TSecond, TThird>();

            foreach (TSource item in source)
            {
                dictionary.Add(firstSelector(item), secondSelector(item), thirdSelector(item));
            }
            return(dictionary);
        }
        public TripleList <string, string, string> GetSubscribers()
        {
            var userReceiveNewsletters = membershipService.GetProfileEntriesByKey(NewsletterUserProfileProvider.ReceiveNewsletters);
            var userLanguages          = membershipService.GetProfileEntriesByKey(SecurityUserProfileProvider.PreferredLanguage);

            var result = new TripleList <string, string, string>();

            if (!userReceiveNewsletters.IsNullOrEmpty())
            {
                var userIds = userReceiveNewsletters.Where(x => bool.Parse(x.Value)).Select(x => x.UserId);
                var users   = membershipService.GetUsers(userIds);

                foreach (var user in users)
                {
                    var preferredLanguage = userLanguages.FirstOrDefault(x => x.UserId == user.Id);

                    result.Add(new Triple <string, string, string>(
                                   user.ToString(),
                                   user.Email,
                                   preferredLanguage == null
                            ? string.Empty
                            : preferredLanguage.Value));
                }
            }

            return(result);
        }
Example #4
0
        public void TestAddingSingleElement()
        {
            TripleList<int> tripleList = new TripleList<int>();
            const int value = 4;
            tripleList.Add(value);
            Assert.AreEqual(1, tripleList.Count());
            Assert.AreEqual(value, tripleList.Value);

            Assert.IsNull(tripleList.PreviousElement);
            Assert.IsNull(tripleList.MiddleElement);
            Assert.IsNull(tripleList.NextElement);
        }
Example #5
0
 public void TestAddingFiveElements()
 {
     TripleList<int> tripleList = new TripleList<int>();
     int value1 = 1;
     int value2 = 2;
     int value3 = 3;
     int value4 = 4;
     int value5 = 5;
     tripleList.Add(value1);
     tripleList.Add(value2);
     tripleList.Add(value3);
     tripleList.Add(value4);
     tripleList.Add(value5);
     Assert.AreEqual(5, tripleList.Count());
     // checking values
     Assert.AreEqual(value1, tripleList.Value);
     Assert.AreEqual(value2, tripleList.MiddleElement.Value);
     Assert.AreEqual(value3, tripleList.NextElement.Value);
     Assert.AreEqual(value4, tripleList.NextElement.MiddleElement.Value);
     Assert.AreEqual(value5, tripleList.NextElement.NextElement.Value);
 }
Example #6
0
 public void TestListsEnumerator2()
 {
     double[] values = { 1.1, 3.14, 6.13, 9.99999, 99.001 };
     var tripleList = new TripleList<double>();
     int i;
     for (i = 0; i < values.Length; ++i)
     {
         tripleList.Add(values[i]);
     }
     i = 0;
     IEnumerator<double> it = tripleList.GetEnumerator();
     while (it.MoveNext())
     {
         Assert.AreEqual(values[i++], it.Current);
     }
 }
Example #7
0
 public void TestListsEnumerator()
 {
     double[] values = { 1.1, 3.14, 6.13, 9.99999, 99.001 };
     var tripleList = new TripleList<double>();
     int i;
     for (i = 0; i < values.Length; ++i)
     {
         tripleList.Add(values[i]);
     }
     i = 0;
     foreach (double d in tripleList)
     {
         Assert.AreEqual(values[i++], d);
     }
 }
Example #8
0
 public void TestIfNoCycle()
 {
     /** Initialization of the TripleList **/
     const int NUMBER_OF_ELEMENTS = 100;
     TripleList<int> tripleList = new TripleList<int>();
     for (int i = 0; i < NUMBER_OF_ELEMENTS; ++i)
     {
         tripleList.Add(i);
     }
     /** Created 2 TripleLists, first jumps every single element,
     another every two elements, in out case every two elements means every NextElement**/
     TripleList<int> tripleListEverySingleNode = tripleList;
     TripleList<int> tripleListEveryTwoNodes = tripleList.NextElement;
     for (int i = 0; i < NUMBER_OF_ELEMENTS * NUMBER_OF_ELEMENTS; ++i)
     {
         Assert.AreNotSame(tripleListEverySingleNode, tripleListEveryTwoNodes);
         JumpToNextElement(ref tripleListEverySingleNode);
         if (null == tripleListEveryTwoNodes.NextElement)
         {
             // if list has end means there are no cycles
             break;
         }
         else
         {
             tripleListEveryTwoNodes = tripleListEveryTwoNodes.NextElement;
         }
     }
 }