[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Constraints / CollectionItemsEqualConstraint.cs
1 // ***********************************************************************
2 // Copyright (c) 2007 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32
33 namespace NUnit.Framework.Constraints
34 {
35     /// <summary>
36     /// CollectionItemsEqualConstraint is the abstract base class for all
37     /// collection constraints that apply some notion of item equality
38     /// as a part of their operation.
39     /// </summary>
40     public abstract class CollectionItemsEqualConstraint : CollectionConstraint
41     {
42         private readonly NUnitEqualityComparer comparer = NUnitEqualityComparer.Default;
43
44         /// <summary>
45         /// Construct an empty CollectionConstraint
46         /// </summary>
47         protected CollectionItemsEqualConstraint() { }
48
49         /// <summary>
50         /// Construct a CollectionConstraint
51         /// </summary>
52         /// <param name="arg"></param>
53         protected CollectionItemsEqualConstraint(object arg) : base(arg) { }
54
55         #region Modifiers
56
57         /// <summary>
58         /// Flag the constraint to ignore case and return self.
59         /// </summary>
60         public CollectionItemsEqualConstraint IgnoreCase
61         {
62             get
63             {
64                 comparer.IgnoreCase = true;
65                 return this;
66             }
67         }
68
69         /// <summary>
70         /// Flag the constraint to use the supplied IComparer object.
71         /// </summary>
72         /// <param name="comparer">The IComparer object to use.</param>
73         /// <returns>Self.</returns>
74         public CollectionItemsEqualConstraint Using(IComparer comparer)
75         {
76             this.comparer.ExternalComparers.Add(EqualityAdapter.For(comparer));
77             return this;
78         }
79
80         /// <summary>
81         /// Flag the constraint to use the supplied IComparer object.
82         /// </summary>
83         /// <param name="comparer">The IComparer object to use.</param>
84         /// <returns>Self.</returns>
85         public CollectionItemsEqualConstraint Using<T>(IComparer<T> comparer)
86         {
87             this.comparer.ExternalComparers.Add(EqualityAdapter.For(comparer));
88             return this;
89         }
90
91         /// <summary>
92         /// Flag the constraint to use the supplied Comparison object.
93         /// </summary>
94         /// <param name="comparer">The IComparer object to use.</param>
95         /// <returns>Self.</returns>
96         public CollectionItemsEqualConstraint Using<T>(Comparison<T> comparer)
97         {
98             this.comparer.ExternalComparers.Add(EqualityAdapter.For(comparer));
99             return this;
100         }
101
102         /// <summary>
103         /// Flag the constraint to use the supplied IEqualityComparer object.
104         /// </summary>
105         /// <param name="comparer">The IComparer object to use.</param>
106         /// <returns>Self.</returns>
107         public CollectionItemsEqualConstraint Using(IEqualityComparer comparer)
108         {
109             this.comparer.ExternalComparers.Add(EqualityAdapter.For(comparer));
110             return this;
111         }
112
113         /// <summary>
114         /// Flag the constraint to use the supplied IEqualityComparer object.
115         /// </summary>
116         /// <param name="comparer">The IComparer object to use.</param>
117         /// <returns>Self.</returns>
118         public CollectionItemsEqualConstraint Using<T>(IEqualityComparer<T> comparer)
119         {
120             this.comparer.ExternalComparers.Add(EqualityAdapter.For(comparer));
121             return this;
122         }
123
124         internal CollectionItemsEqualConstraint Using(EqualityAdapter adapter)
125         {
126             comparer.ExternalComparers.Add(adapter);
127             return this;
128         }
129
130         #endregion
131
132         /// <summary>
133         /// Compares two collection members for equality
134         /// </summary>
135         protected bool ItemsEqual(object x, object y)
136         {
137             Tolerance tolerance = Tolerance.Default;
138             return comparer.AreEqual(x, y, ref tolerance);
139         }
140
141         /// <summary>
142         /// Return a new CollectionTally for use in making tests
143         /// </summary>
144         /// <param name="c">The collection to be included in the tally</param>
145         protected CollectionTally Tally(IEnumerable c)
146         {
147             return new CollectionTally(comparer, c);
148         }
149     }
150 }