Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C# 4.0

Util Library and Extension Methods

Rate me:
Please Sign up or sign in to vote.
4.86/5 (49 votes)
7 May 2013CPOL2 min read 47.8K   1.6K   131  
A simple Util library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NumberExtensions.Collections;

namespace TestExtensions
{
    public partial class Number
    {
        [Test]
        public void TEST_INTEGER_SORT_STRATEGIES()
        {
            IEnumerable<int> integerList = new List<int> { 1, 2, 20, 3, 6, 20 };
            IEnumerable<int> sortedList = new List<int> { 1, 2, 3, 6, 20, 20 };

            Assert.AreEqual(sortedList, integerList.Sort(SortMethod.Bubble));
            Assert.AreEqual(sortedList, integerList.Sort(SortMethod.Insertion));
            Assert.AreEqual(sortedList, integerList.Sort(SortMethod.Selection));
        }
        [Test]
        public void TEST_LONG_SORT_STRATEGIES()
        {
            IEnumerable<long> longList = new List<long> { 1, 2, 20, 3, 6, 20 };
            IEnumerable<long> sortedList = new List<long> { 1, 2, 3, 6, 20, 20 };

            Assert.AreEqual(sortedList, longList.Sort(SortMethod.Bubble));
            Assert.AreEqual(sortedList, longList.Sort(SortMethod.Insertion));
            Assert.AreEqual(sortedList, longList.Sort(SortMethod.Selection));
        }
        [Test]
        public void TEST_DOUBLE_SORT_STRATEGIES()
        {
            IEnumerable<double> doubleList = new List<double> { 1.1, 2.0, 20.3, 3.5, 6.2, 20.3, 20.3 };
            IEnumerable<double> sortedList = new List<double> { 1.1, 2.0, 3.5, 6.2, 20.3, 20.3, 20.3 };

            Assert.AreEqual(sortedList, doubleList.Sort(SortMethod.Bubble));
            Assert.AreEqual(sortedList, doubleList.Sort(SortMethod.Insertion));
            Assert.AreEqual(sortedList, doubleList.Sort(SortMethod.Selection));
        }
        [Test]
        public void TEST_FLOAT_SORT_STRATEGIES()
        {
            IEnumerable<float> floatList = new List<float> { 1, 2, 2, 3, 6, 2, 3 };
            IEnumerable<float> sortedList = new List<float> { 1, 2, 2, 2, 3, 3, 6 };

            Assert.AreEqual(sortedList, floatList.Sort(SortMethod.Bubble));
            Assert.AreEqual(sortedList, floatList.Sort(SortMethod.Insertion));
            Assert.AreEqual(sortedList, floatList.Sort(SortMethod.Selection));
        }
        [Test]
        public void TEST_DECIMAL_SORT_STRATEGIES()
        {
            IEnumerable<decimal> decimalList = new List<decimal> { 1, 2, 2, 3, 6, 2 };
            IEnumerable<decimal> sortedList = new List<decimal> { 1, 2, 2, 2, 3, 6 };

            Assert.AreEqual(sortedList, decimalList.Sort(SortMethod.Bubble));
            Assert.AreEqual(sortedList, decimalList.Sort(SortMethod.Insertion));
            Assert.AreEqual(sortedList, decimalList.Sort(SortMethod.Selection));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Schneider Electric, GTCI Bangalore
India India
Music is my passion,
Apart from programming I like to read a lot.

Comments and Discussions