[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Assert / Assert.Equality.cs
1 // ***********************************************************************
2 // Copyright (c) 2014 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
24 using System;
25 using NUnit.Framework.Internal;
26
27 namespace NUnit.Framework
28 {
29     public partial class Assert
30     {
31         #region AreEqual
32
33         #region Doubles
34
35         /// <summary>
36         /// Verifies that two doubles are equal considering a delta. If the
37         /// expected value is infinity then the delta value is ignored. If 
38         /// they are not equal then an <see cref="AssertionException"/> is
39         /// thrown.
40         /// </summary>
41         /// <param name="expected">The expected value</param>
42         /// <param name="actual">The actual value</param>
43         /// <param name="delta">The maximum acceptable difference between the
44         /// the expected and the actual</param>
45         /// <param name="message">The message to display in case of failure</param>
46         /// <param name="args">Array of objects to be used in formatting the message</param>
47         public static void AreEqual(double expected, double actual, double delta, string message, params object[] args)
48         {
49             AssertDoublesAreEqual(expected, actual, delta, message, args);
50         }
51
52         /// <summary>
53         /// Verifies that two doubles are equal considering a delta. If the
54         /// expected value is infinity then the delta value is ignored. If 
55         /// they are not equal then an <see cref="AssertionException"/> is
56         /// thrown.
57         /// </summary>
58         /// <param name="expected">The expected value</param>
59         /// <param name="actual">The actual value</param>
60         /// <param name="delta">The maximum acceptable difference between the
61         /// the expected and the actual</param>
62         public static void AreEqual(double expected, double actual, double delta)
63         {
64             AssertDoublesAreEqual(expected, actual, delta, null, null);
65         }
66
67         /// <summary>
68         /// Verifies that two doubles are equal considering a delta. If the
69         /// expected value is infinity then the delta value is ignored. If 
70         /// they are not equal then an <see cref="AssertionException"/> is
71         /// thrown.
72         /// </summary>
73         /// <param name="expected">The expected value</param>
74         /// <param name="actual">The actual value</param>
75         /// <param name="delta">The maximum acceptable difference between the
76         /// the expected and the actual</param>
77         /// <param name="message">The message to display in case of failure</param>
78         /// <param name="args">Array of objects to be used in formatting the message</param>
79         public static void AreEqual(double expected, double? actual, double delta, string message, params object[] args)
80         {
81             AssertDoublesAreEqual(expected, (double)actual, delta, message, args);
82         }
83
84         /// <summary>
85         /// Verifies that two doubles are equal considering a delta. If the
86         /// expected value is infinity then the delta value is ignored. If 
87         /// they are not equal then an <see cref="AssertionException"/> is
88         /// thrown.
89         /// </summary>
90         /// <param name="expected">The expected value</param>
91         /// <param name="actual">The actual value</param>
92         /// <param name="delta">The maximum acceptable difference between the
93         /// the expected and the actual</param>
94         public static void AreEqual(double expected, double? actual, double delta)
95         {
96             AssertDoublesAreEqual(expected, (double)actual, delta, null, null);
97         }
98
99         #endregion
100
101         #region Objects
102
103         /// <summary>
104         /// Verifies that two objects are equal.  Two objects are considered
105         /// equal if both are null, or if both have the same value. NUnit
106         /// has special semantics for some object types.
107         /// If they are not equal an <see cref="AssertionException"/> is thrown.
108         /// </summary>
109         /// <param name="expected">The value that is expected</param>
110         /// <param name="actual">The actual value</param>
111         /// <param name="message">The message to display in case of failure</param>
112         /// <param name="args">Array of objects to be used in formatting the message</param>
113         public static void AreEqual(object expected, object actual, string message, params object[] args)
114         {
115             Assert.That(actual, Is.EqualTo(expected), message, args);
116         }
117
118         /// <summary>
119         /// Verifies that two objects are equal.  Two objects are considered
120         /// equal if both are null, or if both have the same value. NUnit
121         /// has special semantics for some object types.
122         /// If they are not equal an <see cref="AssertionException"/> is thrown.
123         /// </summary>
124         /// <param name="expected">The value that is expected</param>
125         /// <param name="actual">The actual value</param>
126         public static void AreEqual(object expected, object actual)
127         {
128             Assert.That(actual, Is.EqualTo(expected), null, null);
129         }
130
131         #endregion
132
133         #endregion
134
135         #region AreNotEqual
136
137         #region Objects
138
139         /// <summary>
140         /// Verifies that two objects are not equal.  Two objects are considered
141         /// equal if both are null, or if both have the same value. NUnit
142         /// has special semantics for some object types.
143         /// If they are equal an <see cref="AssertionException"/> is thrown.
144         /// </summary>
145         /// <param name="expected">The value that is expected</param>
146         /// <param name="actual">The actual value</param>
147         /// <param name="message">The message to display in case of failure</param>
148         /// <param name="args">Array of objects to be used in formatting the message</param>
149         public static void AreNotEqual(object expected, object actual, string message, params object[] args)
150         {
151             Assert.That(actual, Is.Not.EqualTo(expected), message, args);
152         }
153
154         /// <summary>
155         /// Verifies that two objects are not equal.  Two objects are considered
156         /// equal if both are null, or if both have the same value. NUnit
157         /// has special semantics for some object types.
158         /// If they are equal an <see cref="AssertionException"/> is thrown.
159         /// </summary>
160         /// <param name="expected">The value that is expected</param>
161         /// <param name="actual">The actual value</param>
162         public static void AreNotEqual(object expected, object actual)
163         {
164             Assert.That(actual, Is.Not.EqualTo(expected), null, null);
165         }
166
167         #endregion
168
169         #endregion
170
171         #region AreSame
172
173         /// <summary>
174         /// Asserts that two objects refer to the same object. If they
175         /// are not the same an <see cref="AssertionException"/> is thrown.
176         /// </summary>
177         /// <param name="expected">The expected object</param>
178         /// <param name="actual">The actual object</param>
179         /// <param name="message">The message to display in case of failure</param>
180         /// <param name="args">Array of objects to be used in formatting the message</param>
181         public static void AreSame(object expected, object actual, string message, params object[] args)
182         {
183             Assert.That(actual, Is.SameAs(expected), message, args);
184         }
185
186         /// <summary>
187         /// Asserts that two objects refer to the same object. If they
188         /// are not the same an <see cref="AssertionException"/> is thrown.
189         /// </summary>
190         /// <param name="expected">The expected object</param>
191         /// <param name="actual">The actual object</param>
192         public static void AreSame(object expected, object actual)
193         {
194             Assert.That(actual, Is.SameAs(expected), null, null);
195         }
196
197         #endregion
198
199         #region AreNotSame
200
201         /// <summary>
202         /// Asserts that two objects do not refer to the same object. If they
203         /// are the same an <see cref="AssertionException"/> is thrown.
204         /// </summary>
205         /// <param name="expected">The expected object</param>
206         /// <param name="actual">The actual object</param>
207         /// <param name="message">The message to display in case of failure</param>
208         /// <param name="args">Array of objects to be used in formatting the message</param>
209         public static void AreNotSame(object expected, object actual, string message, params object[] args)
210         {
211             Assert.That(actual, Is.Not.SameAs(expected), message, args);
212         }
213
214         /// <summary>
215         /// Asserts that two objects do not refer to the same object. If they
216         /// are the same an <see cref="AssertionException"/> is thrown.
217         /// </summary>
218         /// <param name="expected">The expected object</param>
219         /// <param name="actual">The actual object</param>
220         public static void AreNotSame(object expected, object actual)
221         {
222             Assert.That(actual, Is.Not.SameAs(expected), null, null);
223         }
224
225         #endregion
226
227         #region Helper Methods
228
229         /// <summary>
230         /// Helper for Assert.AreEqual(double expected, double actual, ...)
231         /// allowing code generation to work consistently.
232         /// </summary>
233         /// <param name="expected">The expected value</param>
234         /// <param name="actual">The actual value</param>
235         /// <param name="delta">The maximum acceptable difference between the
236         /// the expected and the actual</param>
237         /// <param name="message">The message to display in case of failure</param>
238         /// <param name="args">Array of objects to be used in formatting the message</param>
239         protected static void AssertDoublesAreEqual(double expected, double actual, double delta, string message, object[] args)
240         {
241             if (double.IsNaN(expected) || double.IsInfinity(expected))
242                 Assert.That(actual, Is.EqualTo(expected), message, args);
243             else
244                 Assert.That(actual, Is.EqualTo(expected).Within(delta), message, args);
245         }
246
247         private static void IncrementAssertCount()
248         {
249             TestExecutionContext.CurrentContext.IncrementAssertCount();
250         }
251
252         #endregion
253     }
254 }