[16407] | 1 | using System;
|
---|
[17584] | 2 | using System.Collections.Generic;
|
---|
[16407] | 3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 4 |
|
---|
| 5 | namespace 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")]
|
---|
[17350] | 17 | public void AddIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 31 | public void SubtractIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 45 | public void MultiplyIntervalTest() {
|
---|
[16407] | 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));
|
---|
[16646] | 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)));
|
---|
[16407] | 57 | }
|
---|
| 58 |
|
---|
| 59 | [TestMethod]
|
---|
| 60 | [TestCategory("Problems.DataAnalysis")]
|
---|
| 61 | [TestProperty("Time", "short")]
|
---|
[17350] | 62 | public void DivideIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 83 | public void SineIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 101 | public void CosineIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 110 | public void LogIntervalTest() {
|
---|
[16407] | 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")]
|
---|
[17350] | 125 | public void ExponentialIntervalTest() {
|
---|
[16407] | 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 | }
|
---|
[16631] | 129 |
|
---|
| 130 |
|
---|
| 131 | [TestMethod]
|
---|
| 132 | [TestCategory("Problems.DataAnalysis")]
|
---|
| 133 | [TestProperty("Time", "short")]
|
---|
[17350] | 134 | public void SquareIntervalTest() {
|
---|
[16631] | 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")]
|
---|
[17350] | 143 | public void SquarerootIntervalTest() {
|
---|
[17584] | 144 | Assert.AreEqual<Interval>(new Interval(-2, 2), Interval.SquareRoot(new Interval(1, 4)));
|
---|
[16631] | 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")]
|
---|
[17350] | 151 | public void CubeIntervalTest() {
|
---|
[16631] | 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")]
|
---|
[17350] | 160 | public void CubeRootIntervalTest() {
|
---|
[16631] | 161 | Assert.AreEqual<Interval>(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8)));
|
---|
[17302] | 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)));
|
---|
[16631] | 168 | }
|
---|
[17306] | 169 |
|
---|
| 170 | [TestMethod]
|
---|
| 171 | [TestCategory("Problems.DataAnalysis")]
|
---|
| 172 | [TestProperty("Time", "short")]
|
---|
[17350] | 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)));
|
---|
[17306] | 179 | }
|
---|
[17348] | 180 |
|
---|
| 181 | [TestMethod]
|
---|
| 182 | [TestCategory("Problems.DataAnalysis")]
|
---|
| 183 | [TestProperty("Time", "short")]
|
---|
[17350] | 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 |
|
---|
[17348] | 194 | //Second interval goes over zero
|
---|
[17584] | 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));
|
---|
[17350] | 209 | }
|
---|
[17348] | 210 |
|
---|
[17350] | 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);
|
---|
[17348] | 219 | }
|
---|
[17350] | 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);
|
---|
[17584] | 253 | }
|
---|
[17350] | 254 |
|
---|
[17584] | 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));
|
---|
[17350] | 291 | }
|
---|
[17584] | 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 EqualsTest() {
|
---|
| 315 | var interval1 = new Interval(0, 12);
|
---|
| 316 | var interval2 = new Interval(-12, 8);
|
---|
| 317 | var interval3 = new Interval(double.NegativeInfinity, 0);
|
---|
| 318 |
|
---|
| 319 | Assert.AreEqual(true, interval1.Equals(new Interval(0, 12)));
|
---|
| 320 | Assert.AreEqual(false, interval1.Equals(interval2));
|
---|
| 321 | Assert.AreEqual(true, interval3 == new Interval(double.NegativeInfinity, 0));
|
---|
| 322 | Assert.AreEqual(true, interval1 != interval2);
|
---|
| 323 | Assert.AreEqual(false, interval2 == interval3);
|
---|
| 324 | Assert.AreEqual(false, interval1 != new Interval(0, 12));
|
---|
| 325 | }
|
---|
| 326 | //[TestMethod]
|
---|
| 327 | //[TestCategory("Problems.DataAnalysis")]
|
---|
| 328 | //[TestProperty("Time", "short")]
|
---|
| 329 | //public void RootTest() {
|
---|
| 330 | // var posInterval = new Interval(3, 5);
|
---|
| 331 | // var negInterval = new Interval(-6, -2);
|
---|
| 332 | // var posIntervalConst = new Interval(5, 5);
|
---|
| 333 | // var negIntervalConst = new Interval(-3, -3);
|
---|
| 334 | // var zeroIntervalConst = new Interval(0, 0);
|
---|
| 335 | // var zeroPosInterval = new Interval(0, 2);
|
---|
| 336 | // var zeroNegInterval = new Interval(-2, 0);
|
---|
| 337 |
|
---|
| 338 | // var posRoot = new Interval(4, 4);
|
---|
| 339 | // var negRoot = new Interval(-4, -4);
|
---|
| 340 | // var zeroRoot = new Interval(0, 0);
|
---|
| 341 | // var oneRoot = new Interval(1, 1);
|
---|
| 342 |
|
---|
| 343 | // Assert.AreEqual(Interval.Root(posInterval, posRoot), new Interval(Math.Pow(3, (1.0/4)), Math.Pow(5, (1.0/4))));
|
---|
| 344 | // Assert.AreEqual(Interval.Root(posInterval, negRoot), new Interval(Math.Pow(5, -(1.0/4)), Math.Pow(3, -(1.0/4))));
|
---|
| 345 | // Assert.AreEqual(Interval.Root(posInterval, zeroRoot), new Interval(double.NaN, double.NaN));
|
---|
| 346 | // Assert.AreEqual(Interval.Root(posInterval, oneRoot), new Interval(3, 5));
|
---|
| 347 |
|
---|
| 348 | // Assert.AreEqual(Interval.Root(negInterval, posRoot), new Interval(Math.Pow(-6, (1.0 / 4)), Math.Pow(-2, (1.0 / 4))));
|
---|
| 349 | // Assert.AreEqual(Interval.Root(negInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), Math.Pow(-6, -(1.0 / 4))));
|
---|
| 350 | // Assert.AreEqual(Interval.Root(negInterval, zeroRoot), new Interval(double.NaN, double.NaN));
|
---|
| 351 | // Assert.AreEqual(Interval.Root(negInterval, oneRoot), new Interval(-6, -2));
|
---|
| 352 |
|
---|
| 353 | // Assert.AreEqual(Interval.Root(posIntervalConst, posRoot), new Interval(Math.Pow(5, (1.0 / 4)), Math.Pow(5, (1.0 / 4))));
|
---|
| 354 | // Assert.AreEqual(Interval.Root(posIntervalConst, negRoot), new Interval(Math.Pow(5, -(1.0 / 4)), Math.Pow(5, -(1.0 / 4))));
|
---|
| 355 | // Assert.AreEqual(Interval.Root(posIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
|
---|
| 356 | // Assert.AreEqual(Interval.Root(posIntervalConst, oneRoot), new Interval(5, 5));
|
---|
| 357 |
|
---|
| 358 | // Assert.AreEqual(Interval.Root(negIntervalConst, posRoot), new Interval(Math.Pow(-3, (1.0 / 4)), Math.Pow(-3, (1.0 / 4))));
|
---|
| 359 | // Assert.AreEqual(Interval.Root(negIntervalConst, negRoot), new Interval(Math.Pow(-3, -(1.0 / 4)), Math.Pow(-3, -(1.0 / 4))));
|
---|
| 360 | // Assert.AreEqual(Interval.Root(negIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
|
---|
| 361 | // Assert.AreEqual(Interval.Root(negIntervalConst, oneRoot), new Interval(-3, -3));
|
---|
| 362 |
|
---|
| 363 | // Assert.AreEqual(Interval.Root(zeroIntervalConst, posRoot), new Interval(0, 0));
|
---|
| 364 | // //Compley Infinity https://www.wolframalpha.com/input/?i=root%28-4%2C+0%29
|
---|
| 365 | // Assert.AreEqual(Interval.Root(zeroIntervalConst, negRoot), new Interval(double.PositiveInfinity, double.PositiveInfinity));
|
---|
| 366 | // Assert.AreEqual(Interval.Root(zeroIntervalConst, zeroRoot), new Interval(0, 0));
|
---|
| 367 | // Assert.AreEqual(Interval.Root(zeroIntervalConst, oneRoot), new Interval(0, 0));
|
---|
| 368 |
|
---|
| 369 | // Assert.AreEqual(Interval.Root(zeroPosInterval, posRoot), new Interval(0, Math.Pow(2, (1.0 / 4))));
|
---|
| 370 | // //Check for complex infinity
|
---|
| 371 | // Assert.AreEqual(Interval.Root(zeroPosInterval, negRoot), new Interval(Math.Pow(2, -(1.0 / 4)), double.PositiveInfinity));
|
---|
| 372 | // Assert.AreEqual(Interval.Root(zeroPosInterval, zeroRoot), new Interval(0, 0));
|
---|
| 373 | // Assert.AreEqual(Interval.Root(zeroPosInterval, oneRoot), new Interval(0, 2));
|
---|
| 374 |
|
---|
| 375 | // Assert.AreEqual(Interval.Root(zeroNegInterval, posRoot), new Interval(Math.Pow(-2, (1.0 / 4)),0));
|
---|
| 376 | // //Check for complex infinity
|
---|
| 377 | // Assert.AreEqual(Interval.Root(zeroNegInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), double.PositiveInfinity));
|
---|
| 378 | // Assert.AreEqual(Interval.Root(zeroNegInterval, zeroRoot), new Interval(double.NaN, double.NaN));
|
---|
| 379 | // Assert.AreEqual(Interval.Root(zeroNegInterval, oneRoot), new Interval(-2, 0));
|
---|
| 380 | //}
|
---|
[16407] | 381 | }
|
---|
| 382 | }
|
---|