Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3107_LearningALPS/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/IntervalTest.cs

Last change on this file was 17754, checked in by chaider, 4 years ago

#2971 Added some trigonometric function tests for IA

File size: 23.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using Microsoft.VisualStudio.TestTools.UnitTesting;
4
5namespace HeuristicLab.Problems.DataAnalysis.Tests {
6  [TestClass]
7  public class IntervalTest {
8    private readonly Interval a = new Interval(-1, 1);
9    private readonly Interval b = new Interval(-2, 2);
10    private readonly Interval c = new Interval(0, 3);
11    private readonly Interval d = new Interval(1, 3);
12    private readonly Interval e = new Interval(4, 6);
13
14    [TestMethod]
15    [TestCategory("Problems.DataAnalysis")]
16    [TestProperty("Time", "short")]
17    public void AddIntervalTest() {
18      //add        [x1,x2] + [y1,y2] = [x1 + y1,x2 + y2]
19
20      // [-1,1] + [-2,2] = [-3,3]
21      Assert.AreEqual(Interval.Add(a, b), new Interval(-3, 3));
22      //([-1, 1] + [-2, 2]) + [0, 3] = [-3, 6]
23      Assert.AreEqual(Interval.Add(Interval.Add(a, b), c), new Interval(-3, 6));
24      //([-1, 1] + [0, 3]) + [-2, 2] = [-3, 6]
25      Assert.AreEqual(Interval.Add(Interval.Add(a, c), b), new Interval(-3, 6));
26    }
27
28    [TestMethod]
29    [TestCategory("Problems.DataAnalysis")]
30    [TestProperty("Time", "short")]
31    public void SubtractIntervalTest() {
32      //subtract   [x1,x2] − [y1,y2] = [x1 − y2,x2 − y1]
33
34      //[-1, 1] - [-2, 2] = [-3, 3]
35      Assert.AreEqual<Interval>(Interval.Subtract(a, b), new Interval(-3, 3));
36      //([-1, 1] - [-2, 2]) - [0, 3] = [-6, 3]
37      Assert.AreEqual<Interval>(Interval.Subtract(Interval.Subtract(a, b), c), new Interval(-6, 3));
38      //([-1, 1] - [0, 3]) - [-2, 2] = [-6, 3]
39      Assert.AreEqual<Interval>(Interval.Subtract(Interval.Subtract(a, c), b), new Interval(-6, 3));
40    }
41
42    [TestMethod]
43    [TestCategory("Problems.DataAnalysis")]
44    [TestProperty("Time", "short")]
45    public void MultiplyIntervalTest() {
46      //multiply   [x1,x2] * [y1,y2] = [min(x1*y1,x1*y2,x2*y1,x2*y2),max(x1*y1,x1*y2,x2*y1,x2*y2)]
47
48      //[-1, 1] * [-2, 2] = [-2, 2]
49      Assert.AreEqual<Interval>(Interval.Multiply(a, b), new Interval(-2, 2));
50      //([-1, 1] * [-2, 2]) * [0, 3] = [-6, 6]
51      Assert.AreEqual<Interval>(Interval.Multiply(Interval.Multiply(a, b), c), new Interval(-6, 6));
52      //([-1, 1] * [0, 3]) * [-2, 2] = [-6, 6]
53      Assert.AreEqual<Interval>(Interval.Multiply(Interval.Multiply(a, c), b), new Interval(-6, 6));
54
55      // [-2, 0] * [-2, 0]  = [0, 4]
56      Assert.AreEqual<Interval>(new Interval(0, 4), Interval.Multiply(new Interval(-2, 0), new Interval(-2, 0)));
57    }
58
59    [TestMethod]
60    [TestCategory("Problems.DataAnalysis")]
61    [TestProperty("Time", "short")]
62    public void DivideIntervalTest() {
63      //divide  [x1, x2] / [y1, y2] = [x1, x2] * (1/[y1, y2]), where 1 / [y1,y2] = [1 / y2,1 / y1] if 0 not in [y_1, y_2].
64
65      //[4, 6] / [1, 3] = [4/3, 6]
66      Assert.AreEqual<Interval>(Interval.Divide(e, d), new Interval(4.0 / 3.0, 6));
67      //([4, 6] / [1, 3]) / [1, 3] = [4/9, 6]
68      Assert.AreEqual<Interval>(Interval.Divide(Interval.Divide(e, d), d), new Interval(4.0 / 9.0, 6));
69      //[4, 6] / [0, 3] = [4/3, +Inf]
70      Assert.AreEqual<Interval>(Interval.Divide(e, c), new Interval(4.0 / 3.0, double.PositiveInfinity));
71      //[-1, 1] / [0, 3] = [+Inf, -Inf]
72      Assert.AreEqual<Interval>(Interval.Divide(a, c), new Interval(double.NegativeInfinity, double.PositiveInfinity));
73      //Devision by 0 ==> IsInfiniteOrUndefined == true
74      Assert.IsTrue(Interval.Divide(e, c).IsInfiniteOrUndefined);
75      //Devision by 0 ==> IsInfiniteOrUndefined == true
76      Assert.IsTrue(Interval.Divide(a, c).IsInfiniteOrUndefined);
77      Assert.AreEqual<Interval>(Interval.Divide(d, b), new Interval(double.NegativeInfinity, double.PositiveInfinity));
78    }
79
80    [TestMethod]
81    [TestCategory("Problems.DataAnalysis")]
82    [TestProperty("Time", "short")]
83    public void SineIntervalTest() {
84      //sine depends on interval
85      //sin([0, 2*pi]) = [-1, 1]
86      Assert.AreEqual<Interval>(Interval.Sine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1));
87      //sin([-pi/2, pi/2]) = [sin(-pi/2), sin(pi/2)]
88      Assert.AreEqual<Interval>(Interval.Sine(new Interval(-1 * Math.PI / 2, Math.PI / 2)), new Interval(-1, 1));
89      //sin([0, pi/2]) = [sin(0), sin(pi/2)]
90      Assert.AreEqual<Interval>(Interval.Sine(new Interval(0, Math.PI / 2)), new Interval(0, 1));
91      //sin([pi, 3*pi/2]) = [sin(pi), sin(3*pi/2)]
92      Assert.AreEqual<Interval>(Interval.Sine(new Interval(Math.PI, 3 * Math.PI / 2)), new Interval(-1, 0));
93      Assert.AreEqual<Interval>(Interval.Sine(new Interval(1, 2)), new Interval(Math.Min(Math.Sin(1), Math.Sin(2)), 1));
94      Assert.AreEqual<Interval>(Interval.Sine(new Interval(1, 3)), new Interval(Math.Min(Math.Sin(1), Math.Sin(3)), 1));
95      Assert.AreEqual<Interval>(Interval.Sine(new Interval(Math.PI, 5 * Math.PI / 2)), new Interval(-1, 1));
96    }
97
98    [TestMethod]
99    [TestCategory("Problems.DataAnalysis")]
100    [TestProperty("Time", "short")]
101    public void CosineIntervalTest() {
102      //Cosine uses sine Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2)));
103      Assert.AreEqual<Interval>(Interval.Cosine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1));
104      Assert.AreEqual<Interval>(new Interval(-1, 1), Interval.Cosine(new Interval(Math.PI, 4 * Math.PI / 2)));
105    }
106
107    [TestMethod]
108    [TestCategory("Problems.DataAnalysis")]
109    [TestProperty("Time", "short")]
110    public void LogIntervalTest() {
111      //Log([3, 5]) = [log(3), log(5)]
112      Assert.AreEqual<Interval>(new Interval(Math.Log(3), Math.Log(5)), Interval.Logarithm(new Interval(3, 5)));
113      //Log([0.5, 1]) = [log(0.5), log(1)]
114      Assert.AreEqual<Interval>(new Interval(Math.Log(0.5), 0), Interval.Logarithm(new Interval(0.5, 1)));
115      //Log([-1, 5]) = [NaN, log(5)]
116      var result = Interval.Logarithm(new Interval(-1, 5));
117      Assert.AreEqual<Interval>(new Interval(double.NaN, Math.Log(5)),result);
118      Assert.IsTrue(result.IsInfiniteOrUndefined);
119    }
120
121
122    [TestMethod]
123    [TestCategory("Problems.DataAnalysis")]
124    [TestProperty("Time", "short")]
125    public void ExponentialIntervalTest() {
126      //Exp([0, 1]) = [exp(0), exp(1)]
127      Assert.AreEqual<Interval>(new Interval(1, Math.Exp(1)), Interval.Exponential(new Interval(0, 1)));
128    }
129
130
131    [TestMethod]
132    [TestCategory("Problems.DataAnalysis")]
133    [TestProperty("Time", "short")]
134    public void SquareIntervalTest() {
135      Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(1, 2)));
136      Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(-2, -1)));
137      Assert.AreEqual<Interval>(new Interval(0, 4), Interval.Square(new Interval(-2, 2)));
138    }
139
140    [TestMethod]
141    [TestCategory("Problems.DataAnalysis")]
142    [TestProperty("Time", "short")]
143    public void SquarerootIntervalTest() {
144      Assert.AreEqual<Interval>(new Interval(-2, 2), Interval.SquareRoot(new Interval(1, 4)));
145      Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1)));
146    }
147
148    [TestMethod]
149    [TestCategory("Problems.DataAnalysis")]
150    [TestProperty("Time", "short")]
151    public void CubeIntervalTest() {
152      Assert.AreEqual<Interval>(new Interval(1, 8), Interval.Cube(new Interval(1, 2)));
153      Assert.AreEqual<Interval>(new Interval(-8, -1), Interval.Cube(new Interval(-2, -1)));
154      Assert.AreEqual<Interval>(new Interval(-8, 8), Interval.Cube(new Interval(-2, 2)));
155    }
156
157    [TestMethod]
158    [TestCategory("Problems.DataAnalysis")]
159    [TestProperty("Time", "short")]
160    public void CubeRootIntervalTest() {
161      Assert.AreEqual<Interval>(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8)));
162      Assert.AreEqual<Interval>(new Interval(-2, -2), Interval.CubicRoot(new Interval(-8, -8)));
163      Assert.AreEqual<Interval>(new Interval(-2, 2), Interval.CubicRoot(new Interval(-8, 8)));
164      Assert.AreEqual(new Interval(2, 2), Interval.CubicRoot(new Interval(8, 8)));
165      Assert.AreEqual(new Interval(-Math.Pow(6, 1.0 / 3), 2), Interval.CubicRoot(new Interval(-6, 8)));
166      Assert.AreEqual(new Interval(2, 2), Interval.CubicRoot(new Interval(8, 8)));
167      Assert.AreEqual(new Interval(-2, 0), Interval.CubicRoot(new Interval(-8, 0)));
168    }
169
170    [TestMethod]
171    [TestCategory("Problems.DataAnalysis")]
172    [TestProperty("Time", "short")]
173    public void AbsoluteIntervalTest() {
174      Assert.AreEqual(new Interval(2, 5), Interval.Absolute(new Interval(-5, -2)));
175      Assert.AreEqual(new Interval(2, 5), Interval.Absolute(new Interval(2, 5)));
176      Assert.AreEqual(new Interval(0, 3), Interval.Absolute(new Interval(-3, 0)));
177      Assert.AreEqual(new Interval(0, 5), Interval.Absolute(new Interval(0, 5)));
178      Assert.AreEqual(new Interval(0, 5), Interval.Absolute(new Interval(-2, 5)));
179    }
180
181    [TestMethod]
182    [TestCategory("Problems.DataAnalysis")]
183    [TestProperty("Time", "short")]
184    public void AnalyticalQuotientIntervalTest() {
185      //Analytical Quotient ==> a / sqrt(b^2 + 1)
186      var aPos = new Interval(3, 5);
187      var aZero = new Interval(-3, 5);
188      var aNeg = new Interval(-5, -3);
189
190      var bPos = new Interval(2, 4);
191      var bZero = new Interval(-2, 4);
192      var bNeg = new Interval(-4, -2);
193
194      //Second interval goes over zero
195      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound), Interval.AnalyticalQuotient(aPos, bZero));
196      //Assert.AreEqual(new Interval(aZero.LowerBound, aZero.UpperBound), Interval.AnalyticalQuotient(aZero, bZero));
197      //Assert.AreEqual(new Interval(aNeg.LowerBound, aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bZero));
198      ////Second interval is positive
199      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bPos));
200      //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bPos));
201      //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bPos));
202      ////Second interval is negative
203      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bNeg));
204      //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bNeg));
205      //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bNeg));
206      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aPos, bZero));
207      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aPos, bPos));
208      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aZero, bNeg));
209    }
210
211    [TestMethod]
212    [TestCategory("Problems.DataAnalysis")]
213    [TestProperty("Time", "short")]
214    public void IsNegativeIntervalTest() {
215      Assert.IsTrue(new Interval(-2, -1).IsNegative);
216      Assert.IsFalse(new Interval(-2, 0).IsNegative);
217      Assert.IsFalse(new Interval(-2, 2).IsNegative);
218      Assert.IsFalse(new Interval(2, 4).IsNegative);
219    }
220
221    [TestMethod]
222    [TestCategory("Problems.DataAnalysis")]
223    [TestProperty("Time", "short")]
224    public void IsPositiveIntervalTest() {
225      Assert.IsTrue(new Interval(3, 5).IsPositive);
226      Assert.IsFalse(new Interval(0, 5).IsPositive);
227      Assert.IsFalse(new Interval(-1, 5).IsPositive);
228      Assert.IsFalse(new Interval(-5, -2).IsPositive);
229    }
230
231    [TestMethod]
232    [TestCategory("Problems.DataAnalysis")]
233    [TestProperty("Time", "short")]
234    public void IsAlmostIntervalTest() {
235      var negativeLowerBound = -2E-13;
236      var negativeUpperBound = -1E-13;
237      var positiveLowerBound = 3E-13;
238      var positiveUpperBound = 5E-13;
239
240      var negativeInterval = new Interval(negativeLowerBound, negativeUpperBound);
241      var positiveInterval = new Interval(positiveLowerBound, positiveUpperBound);
242      var zeroInterval = new Interval(negativeUpperBound, positiveLowerBound);
243
244      //Check for right-shift of negative interval
245      Assert.AreEqual(negativeUpperBound, negativeInterval.LowerBound);
246      Assert.AreEqual(negativeUpperBound, negativeInterval.UpperBound);
247      //Check for left-shift of positive interval
248      Assert.AreEqual(positiveLowerBound, positiveInterval.LowerBound);
249      Assert.AreEqual(positiveLowerBound, positiveInterval.UpperBound);
250      //Check for setting interval to zero
251      Assert.AreEqual(0, zeroInterval.LowerBound);
252      Assert.AreEqual(0, zeroInterval.UpperBound);
253    }
254
255    [TestMethod]
256    [TestCategory("Problems.DataAnalysis")]
257    [TestProperty("Time", "short")]
258    public void ContaintsTest() {
259      var negativeInterval = new Interval(-10, -5);
260      var positiveInterval = new Interval(5, 10);
261      var overZeroInterval = new Interval(-5, 5);
262
263      //Tests for negative intervals
264      Assert.AreEqual(true, negativeInterval.Contains(new Interval(-9, -7)));
265      Assert.AreEqual(false, negativeInterval.Contains(new Interval(-11, -3)));
266      Assert.AreEqual(false, negativeInterval.Contains(positiveInterval));
267      Assert.AreEqual(false, negativeInterval.Contains(overZeroInterval));
268      Assert.AreEqual(true, negativeInterval.Contains(-8));
269      Assert.AreEqual(false, negativeInterval.Contains(-12));
270      Assert.AreEqual(false, negativeInterval.Contains(0));
271      //Testes for positive intervals
272      Assert.AreEqual(true, positiveInterval.Contains(new Interval(6, 10)));
273      Assert.AreEqual(false, positiveInterval.Contains(new Interval(6, 12)));
274      Assert.AreEqual(false, positiveInterval.Contains(negativeInterval));
275      Assert.AreEqual(false, positiveInterval.Contains(overZeroInterval));
276      Assert.AreEqual(true, positiveInterval.Contains(7));
277      Assert.AreEqual(false, positiveInterval.Contains(11));
278      Assert.AreEqual(false, positiveInterval.Contains(0));
279      //Tests for over zero intervals
280      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-3, 3)));
281      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-4, -1)));
282      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(1, 5)));
283      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-6, 0)));
284      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(0, 6)));
285      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-7, 7)));
286      Assert.AreEqual(true, overZeroInterval.Contains(-3));
287      Assert.AreEqual(true, overZeroInterval.Contains(0));
288      Assert.AreEqual(true, overZeroInterval.Contains(3));
289      Assert.AreEqual(false, overZeroInterval.Contains(12));
290      Assert.AreEqual(false, overZeroInterval.Contains(-7));
291    }
292
293    [TestMethod]
294    [TestCategory("Problems.DataAnalysis")]
295    [TestProperty("Time", "short")]
296    public void GetIntervalTest() {
297      var values = new List<double>() { -2.5, -9, 2, 7, 0 ,12, 12.4, 12.4, 9.29, 1002, -29.9};
298      var valuesNan = new List<double>() { double.NaN, 2, 4, 19, -2, -12.2};
299      var valuesInf = new List<double>() {double.NegativeInfinity, double.PositiveInfinity, 12, 2, -2, -12.2};
300
301      var valuesInterval = new Interval(-29.9, 1002);
302      var valuesNanInterval = new Interval(double.NaN, double.NaN);
303      var valuesInfInterval = new Interval(double.NegativeInfinity, double.PositiveInfinity);
304
305
306      Assert.AreEqual(valuesInterval, Interval.GetInterval(values));
307      Assert.AreEqual(valuesNanInterval, Interval.GetInterval(valuesNan));
308      Assert.AreEqual(valuesInfInterval, Interval.GetInterval(valuesInf));
309    }
310
311    [TestMethod]
312    [TestCategory("Problems.DataAnalysis")]
313    [TestProperty("Time", "short")]
314    public void GeometricTest() {
315      Assert.AreEqual(new Interval(-1, -0.936456687290796), Interval.Cosine(new Interval(3, 3.5)));
316      Assert.AreEqual(new Interval(-1, -0.936456687290796), Interval.Cosine(new Interval(-3.5, -3)));
317      Assert.AreEqual(new Interval(-1, 1), Interval.Cosine(new Interval(-3.5, 3)));
318      Assert.AreEqual(new Interval(-0.839071529076452, 0.843853958732493), Interval.Cosine(new Interval(10, 12)));
319      Assert.AreEqual(new Interval(0.136737218207833, 0.907446781450197), Interval.Cosine(new Interval(13, 14)));
320      Assert.AreEqual(new Interval(-0.839071529076452, 1), Interval.Cosine(new Interval(10, 14)));
321      Assert.AreEqual(new Interval(-1, 0.136737218207833), Interval.Cosine(new Interval(14, 16)));
322      Assert.AreEqual(new Interval(-0.839071529076452, 0.004425697988051), Interval.Cosine(new Interval(-11, -10)));
323      Assert.AreEqual(new Interval(0.136737218207833, 0.907446781450197), Interval.Cosine(new Interval(-14, -13)));
324      Assert.AreEqual(new Interval(-1, 0.136737218207833), Interval.Cosine(new Interval(-16, -14)));
325      Assert.AreEqual(new Interval(0.101585703696621, 1), Interval.Cosine(new Interval(-102, -100)));
326      Assert.AreEqual(new Interval(-1, 1), Interval.Cosine(new Interval(4.6e15, 4.7e15)));
327      Assert.AreEqual(new Interval(0.87758256189037265, 0.87758256189037276), Interval.Cosine(new Interval(0.5, 0.5)));
328      Assert.AreEqual(new Interval(-0.09904103659872825, 0.8775825618903728), Interval.Cosine(new Interval(0.5, 1.67)));
329      Assert.AreEqual(new Interval(-1.0, 0.77556587851025016), Interval.Cosine(new Interval(2.1, 5.6)));
330      Assert.AreEqual(new Interval(-1.0, 1.0), Interval.Cosine(new Interval(0.5, 8.5)));
331      Assert.AreEqual(new Interval(-1.0, -0.09904103659872801), Interval.Cosine(new Interval(1.67, 3.2)));
332
333
334      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(double.NegativeInfinity, double.PositiveInfinity)));
335      Assert.AreEqual(new Interval(0, 1.55740772465490223051), Interval.Tangens(new Interval(0, 1)));
336      Assert.AreEqual(new Interval(-1.55740772465490223051, 0), Interval.Tangens(new Interval(-1, 0)));
337      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(-2, -1)));
338      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(202, 203)));
339      Assert.AreEqual(new Interval(0.54630248984379048, 0.5463024898437906), Interval.Tangens(new Interval(0.5, 0.5)));
340      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(0.5,
341        1.67)));
342      //Assert.AreEqual(new Interval(-10.047182299210307, 0.5847385445957865), Interval.Tangens(new Interval(1.67, 3.2)));
343      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(
344        6.638314112824137, 8.38263151220128)));
345
346
347
348      Assert.AreEqual(new Interval(0.47942553860420295, 0.47942553860420301), Interval.Sine(new Interval(0.5, 0.5)));
349      Assert.AreEqual(new Interval(4.7942553860420295e-01, 1.0), Interval.Sine(new Interval(0.5, 1.67)));
350      Assert.AreEqual(new Interval(-5.8374143427580093e-02, 9.9508334981018021e-01), Interval.Sine(new Interval(1.67,
351        3.2)));
352      Assert.AreEqual(new Interval(-1.0, 0.863209366648874), Interval.Sine(new Interval(2.1, 5.6)));
353      Assert.AreEqual(new Interval(-1.0, 1.0), Interval.Sine(new Interval(0.5, 8.5)));
354      Assert.AreEqual(new Interval(-1.0, 0.9775301176650971), Interval.Sine(new Interval(-4.5, 0.1)));
355      Assert.AreEqual(new Interval(-1.0, 1.0), Interval.Sine(new Interval(1.3, 6.3)));
356    }
357
358    [TestMethod]
359    [TestCategory("Problems.DataAnalysis")]
360    [TestProperty("Time", "short")]
361    public void EqualsTest() {
362      var interval1 = new Interval(0, 12);
363      var interval2 = new Interval(-12, 8);
364      var interval3 = new Interval(double.NegativeInfinity, 0);
365
366      Assert.AreEqual(true, interval1.Equals(new Interval(0, 12)));
367      Assert.AreEqual(false, interval1.Equals(interval2));
368      Assert.AreEqual(true, interval3 == new Interval(double.NegativeInfinity, 0));
369      Assert.AreEqual(true, interval1 != interval2);
370      Assert.AreEqual(false, interval2 == interval3);
371      Assert.AreEqual(false, interval1 != new Interval(0, 12));
372    }
373    //[TestMethod]
374    //[TestCategory("Problems.DataAnalysis")]
375    //[TestProperty("Time", "short")]
376    //public void RootTest() {
377    //  var posInterval = new Interval(3, 5);
378    //  var negInterval = new Interval(-6, -2);
379    //  var posIntervalConst = new Interval(5, 5);
380    //  var negIntervalConst = new Interval(-3, -3);
381    //  var zeroIntervalConst = new Interval(0, 0);
382    //  var zeroPosInterval = new Interval(0, 2);
383    //  var zeroNegInterval = new Interval(-2, 0);
384
385    //  var posRoot = new Interval(4, 4);
386    //  var negRoot = new Interval(-4, -4);
387    //  var zeroRoot = new Interval(0, 0);
388    //  var oneRoot = new Interval(1, 1);
389
390    //  Assert.AreEqual(Interval.Root(posInterval, posRoot), new Interval(Math.Pow(3, (1.0/4)), Math.Pow(5, (1.0/4))));
391    //  Assert.AreEqual(Interval.Root(posInterval, negRoot), new Interval(Math.Pow(5, -(1.0/4)), Math.Pow(3, -(1.0/4))));
392    //  Assert.AreEqual(Interval.Root(posInterval, zeroRoot), new Interval(double.NaN, double.NaN));
393    //  Assert.AreEqual(Interval.Root(posInterval, oneRoot), new Interval(3, 5));
394
395    //  Assert.AreEqual(Interval.Root(negInterval, posRoot), new Interval(Math.Pow(-6, (1.0 / 4)), Math.Pow(-2, (1.0 / 4))));
396    //  Assert.AreEqual(Interval.Root(negInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), Math.Pow(-6, -(1.0 / 4))));
397    //  Assert.AreEqual(Interval.Root(negInterval, zeroRoot), new Interval(double.NaN, double.NaN));
398    //  Assert.AreEqual(Interval.Root(negInterval, oneRoot), new Interval(-6, -2));
399
400    //  Assert.AreEqual(Interval.Root(posIntervalConst, posRoot), new Interval(Math.Pow(5, (1.0 / 4)), Math.Pow(5, (1.0 / 4))));
401    //  Assert.AreEqual(Interval.Root(posIntervalConst, negRoot), new Interval(Math.Pow(5, -(1.0 / 4)), Math.Pow(5, -(1.0 / 4))));
402    //  Assert.AreEqual(Interval.Root(posIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
403    //  Assert.AreEqual(Interval.Root(posIntervalConst, oneRoot), new Interval(5, 5));
404
405    //  Assert.AreEqual(Interval.Root(negIntervalConst, posRoot), new Interval(Math.Pow(-3, (1.0 / 4)), Math.Pow(-3, (1.0 / 4))));
406    //  Assert.AreEqual(Interval.Root(negIntervalConst, negRoot), new Interval(Math.Pow(-3, -(1.0 / 4)), Math.Pow(-3, -(1.0 / 4))));
407    //  Assert.AreEqual(Interval.Root(negIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
408    //  Assert.AreEqual(Interval.Root(negIntervalConst, oneRoot), new Interval(-3, -3));
409
410    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, posRoot), new Interval(0, 0));
411    //  //Compley Infinity https://www.wolframalpha.com/input/?i=root%28-4%2C+0%29
412    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, negRoot), new Interval(double.PositiveInfinity, double.PositiveInfinity));
413    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, zeroRoot), new Interval(0, 0));
414    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, oneRoot), new Interval(0, 0));
415
416    //  Assert.AreEqual(Interval.Root(zeroPosInterval, posRoot), new Interval(0, Math.Pow(2, (1.0 / 4))));
417    //  //Check for complex infinity
418    //  Assert.AreEqual(Interval.Root(zeroPosInterval, negRoot), new Interval(Math.Pow(2, -(1.0 / 4)), double.PositiveInfinity));
419    //  Assert.AreEqual(Interval.Root(zeroPosInterval, zeroRoot), new Interval(0, 0));
420    //  Assert.AreEqual(Interval.Root(zeroPosInterval, oneRoot), new Interval(0, 2));
421
422    //  Assert.AreEqual(Interval.Root(zeroNegInterval, posRoot), new Interval(Math.Pow(-2, (1.0 / 4)),0));
423    //  //Check for complex infinity
424    //  Assert.AreEqual(Interval.Root(zeroNegInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), double.PositiveInfinity));
425    //  Assert.AreEqual(Interval.Root(zeroNegInterval, zeroRoot), new Interval(double.NaN, double.NaN));
426    //  Assert.AreEqual(Interval.Root(zeroNegInterval, oneRoot), new Interval(-2, 0));
427    //}
428  }
429}
Note: See TracBrowser for help on using the repository browser.