UtilTests.cs :  » Development » TULP2G » Wintellect » PowerCollections » Tests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » TULP2G 
TULP2G » Wintellect » PowerCollections » Tests » UtilTests.cs
//******************************
// Written by Peter Golde
// Copyright (c) 2004-2005, Wintellect
//
// Use and restribution of this code is subject to the license agreement 
// contained in the file "License.txt" accompanying this file.
//******************************

#region Using directives

using System;
using System.Collections.Generic;
using System.Collections;
using NUnit.Framework;

#endregion

namespace Wintellect.PowerCollections.Tests{
    [TestFixture]
    public class UtilTests
    {
#pragma warning disable 649
        struct StructType {
            public int i;
        }

        class ClassType {
            public int i;
        }

        public struct CloneableStruct : ICloneable
        {
            public int value;
            public int tweak;

            public CloneableStruct(int v)
            {
                value = v;
                tweak = 1;
            }

            public object Clone()
            {
                CloneableStruct newStruct;
                newStruct.value = value;
                newStruct.tweak = tweak + 1;
                return newStruct;
            }

            public bool Identical(CloneableStruct other)
            {
                return value == other.value && tweak == other.tweak;
            }

            public override bool Equals(object other)
            {
                if (! (other is CloneableStruct))
                    return false;
                CloneableStruct o = (CloneableStruct)other;

                return (o.value == value);
            }

            public override int GetHashCode()
            {
                return value.GetHashCode();
            }
        }  

#pragma warning restore 649

        [Test]
        public void IsCloneableType()
        {
            bool isCloneable, isValue;

            isCloneable = Util.IsCloneableType(typeof(int), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsTrue(isValue);

            isCloneable = Util.IsCloneableType(typeof(ICloneable), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsFalse(isValue);

            isCloneable = Util.IsCloneableType(typeof(StructType), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsTrue(isValue);

            isCloneable = Util.IsCloneableType(typeof(ClassType), out isValue);
            Assert.IsFalse(isCloneable); Assert.IsFalse(isValue);

            isCloneable = Util.IsCloneableType(typeof(ArrayList), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsFalse(isValue);

            isCloneable = Util.IsCloneableType(typeof(CloneableStruct), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsFalse(isValue);

            isCloneable = Util.IsCloneableType(typeof(OrderedDictionary<int, double>), out isValue);
            Assert.IsTrue(isCloneable); Assert.IsFalse(isValue);
        }

        [Test]
        public void WrapEnumerable()
        {
            IEnumerable<int> enum1 = new List<int>(new int[] { 1, 4, 5, 6, 9, 1 });
            IEnumerable<int> enum2 = Util.CreateEnumerableWrapper(enum1);
            InterfaceTests.TestEnumerableElements(enum2, new int[] { 1, 4, 5, 6, 9, 1 });
        }

        [Test]
        public void TestGetHashCode()
        {
            int r1, r2, result;
            result = Util.GetHashCode("foo", EqualityComparer<string>.Default);
            Assert.AreEqual(result, "foo".GetHashCode());
            result = Util.GetHashCode(null, EqualityComparer<string>.Default);
            Assert.AreEqual(result, 0x1786E23C);
            r1 = Util.GetHashCode("Banana", StringComparer.InvariantCultureIgnoreCase);
            r2 = Util.GetHashCode("banANA", StringComparer.InvariantCultureIgnoreCase);
            Assert.AreEqual(r1, r2);
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.