Statistics
| Branch: | Revision:

root / trunk / Pithos.Core.Test / ExtensionTests.cs @ 12c87c0e

History | View | Annotate | Download (2.9 kB)

1 b9f5b594 Panagiotis Kanavos
// -----------------------------------------------------------------------
2 b9f5b594 Panagiotis Kanavos
// <copyright file="ExtensionTests.cs" company="GRNet">
3 1cf5689c Panagiotis Kanavos
// Copyright 2011-2012 GRNET S.A. All rights reserved.
4 b9f5b594 Panagiotis Kanavos
// 
5 b9f5b594 Panagiotis Kanavos
// Redistribution and use in source and binary forms, with or
6 b9f5b594 Panagiotis Kanavos
// without modification, are permitted provided that the following
7 b9f5b594 Panagiotis Kanavos
// conditions are met:
8 b9f5b594 Panagiotis Kanavos
// 
9 b9f5b594 Panagiotis Kanavos
//   1. Redistributions of source code must retain the above
10 b9f5b594 Panagiotis Kanavos
//      copyright notice, this list of conditions and the following
11 b9f5b594 Panagiotis Kanavos
//      disclaimer.
12 b9f5b594 Panagiotis Kanavos
// 
13 b9f5b594 Panagiotis Kanavos
//   2. Redistributions in binary form must reproduce the above
14 b9f5b594 Panagiotis Kanavos
//      copyright notice, this list of conditions and the following
15 b9f5b594 Panagiotis Kanavos
//      disclaimer in the documentation and/or other materials
16 b9f5b594 Panagiotis Kanavos
//      provided with the distribution.
17 b9f5b594 Panagiotis Kanavos
// 
18 b9f5b594 Panagiotis Kanavos
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 b9f5b594 Panagiotis Kanavos
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 b9f5b594 Panagiotis Kanavos
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 b9f5b594 Panagiotis Kanavos
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 b9f5b594 Panagiotis Kanavos
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 b9f5b594 Panagiotis Kanavos
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 b9f5b594 Panagiotis Kanavos
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 b9f5b594 Panagiotis Kanavos
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 b9f5b594 Panagiotis Kanavos
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 b9f5b594 Panagiotis Kanavos
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 b9f5b594 Panagiotis Kanavos
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 b9f5b594 Panagiotis Kanavos
// POSSIBILITY OF SUCH DAMAGE.
30 b9f5b594 Panagiotis Kanavos
// 
31 b9f5b594 Panagiotis Kanavos
// The views and conclusions contained in the software and
32 b9f5b594 Panagiotis Kanavos
// documentation are those of the authors and should not be
33 b9f5b594 Panagiotis Kanavos
// interpreted as representing official policies, either expressed
34 b9f5b594 Panagiotis Kanavos
// or implied, of GRNET S.A.
35 b9f5b594 Panagiotis Kanavos
// </copyright>
36 b9f5b594 Panagiotis Kanavos
// -----------------------------------------------------------------------
37 b9f5b594 Panagiotis Kanavos
38 b9f5b594 Panagiotis Kanavos
using System.Collections.Concurrent;
39 b9f5b594 Panagiotis Kanavos
using NUnit.Framework;
40 b9f5b594 Panagiotis Kanavos
41 b9f5b594 Panagiotis Kanavos
namespace Pithos.Core.Test
42 b9f5b594 Panagiotis Kanavos
{
43 b9f5b594 Panagiotis Kanavos
    using System.Linq;
44 b9f5b594 Panagiotis Kanavos
    using Agents;
45 b9f5b594 Panagiotis Kanavos
46 b9f5b594 Panagiotis Kanavos
    /// <summary>
47 b9f5b594 Panagiotis Kanavos
    /// TODO: Update summary.
48 b9f5b594 Panagiotis Kanavos
    /// </summary>
49 b9f5b594 Panagiotis Kanavos
    [TestFixture]    
50 b9f5b594 Panagiotis Kanavos
    public class ExtensionTests
51 b9f5b594 Panagiotis Kanavos
    {
52 b9f5b594 Panagiotis Kanavos
        [Test]
53 b9f5b594 Panagiotis Kanavos
        public void TestRemoveConcurrent()
54 b9f5b594 Panagiotis Kanavos
        {
55 b9f5b594 Panagiotis Kanavos
            var test=new ConcurrentQueue<int>();
56 b9f5b594 Panagiotis Kanavos
            for (var i = 0; i < 100; i++)
57 b9f5b594 Panagiotis Kanavos
            {
58 b9f5b594 Panagiotis Kanavos
              test.Enqueue(i);  
59 b9f5b594 Panagiotis Kanavos
            }
60 b9f5b594 Panagiotis Kanavos
61 b9f5b594 Panagiotis Kanavos
            test.RemoveFirst(t=>t==3);
62 b9f5b594 Panagiotis Kanavos
            Assert.IsFalse(test.Any(t => t == 3),"Item was not removed");
63 b9f5b594 Panagiotis Kanavos
            for (var i=0;i<3;i++)
64 b9f5b594 Panagiotis Kanavos
            {
65 b9f5b594 Panagiotis Kanavos
                int item;
66 b9f5b594 Panagiotis Kanavos
                Assert.IsTrue(test.TryDequeue(out item),"Missing items");
67 b9f5b594 Panagiotis Kanavos
                Assert.AreEqual(i, item,"Preceding items not queued correctly");
68 b9f5b594 Panagiotis Kanavos
            }
69 b9f5b594 Panagiotis Kanavos
            for (var i = 4; i < 100; i++)
70 b9f5b594 Panagiotis Kanavos
            {
71 b9f5b594 Panagiotis Kanavos
                int item;
72 b9f5b594 Panagiotis Kanavos
                Assert.IsTrue(test.TryDequeue(out item), "Missing items");
73 b9f5b594 Panagiotis Kanavos
                Assert.AreEqual(i, item, "Succeeding items not queued correctly");
74 b9f5b594 Panagiotis Kanavos
            }
75 b9f5b594 Panagiotis Kanavos
            
76 b9f5b594 Panagiotis Kanavos
            
77 b9f5b594 Panagiotis Kanavos
        }
78 b9f5b594 Panagiotis Kanavos
    }
79 b9f5b594 Panagiotis Kanavos
}