Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/19 17:03:17 (5 years ago)
Author:
gkronber
Message:

#2994: another unit test for interval arithmetic

Location:
branches/2994-AutoDiffForIntervals/HeuristicLab.Tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/AutoDiffIntervalTest.cs

    r17290 r17293  
    11using System;
     2using System.Collections.Generic;
    23using HeuristicLab.Problems.DataAnalysis.Symbolic;
    34using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    3132        Assert.IsTrue(double.IsNaN(b.LowerBound.Value));
    3233      } else {
    33         Assert.AreEqual(a.LowerBound.Value.Value, b.LowerBound.Value.Value, 1e-10);
     34        Assert.AreEqual(a.LowerBound.Value.Value, b.LowerBound.Value.Value, Math.Abs(a.LowerBound.Value.Value)*1e-4); // relative error < 0.1%
    3435      }
    3536
     
    3738        Assert.IsTrue(double.IsNaN(b.UpperBound.Value));
    3839      } else {
    39         Assert.AreEqual(a.UpperBound.Value.Value, b.UpperBound.Value.Value, 1e-10);
     40        Assert.AreEqual(a.UpperBound.Value.Value, b.UpperBound.Value.Value, Math.Abs(a.UpperBound.Value.Value) * 1e-4);
    4041      }
    4142    }
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/AutoDiffIntervalInterpreterTest.cs

    r17288 r17293  
    209209      EvaluateTest("sqr(R/r)", new Interval(0.2 * 0.2 / (0.8 * 0.8), 0.5 * 0.5 / (0.5 * 0.5)), dataIntervals);
    210210    }
     211
     212
     213
     214    [TestMethod]
     215    [TestCategory("Problems.DataAnalysis")]
     216    [TestProperty("Time", "short")]
     217    public void TestExpressions() {
     218      var parser = new InfixExpressionParser();
     219      var evaluator = new IntervalEvaluator();
     220      var intervals = new Dictionary<string, Interval>() {
     221        {"x", new Interval(1, 2) }
     222      };
     223
     224      var t = parser.Parse("SQR(EXP(CUBE((2.10981074965936*'x'))))");
     225      var r = evaluator.Evaluate(t, intervals);
     226      AssertInterval(143638040.396283, 1.81198989971641E+65, r);
     227    }
     228
     229    private void AssertInterval(double expectedLow, double expectedHigh, Interval r) {
     230      Assert.AreEqual(expectedLow, r.LowerBound, Math.Abs(expectedLow * 1e-5));
     231      Assert.AreEqual(expectedHigh, r.UpperBound, Math.Abs(expectedHigh* 1e-5));
     232    }
    211233  }
    212234}
Note: See TracChangeset for help on using the changeset viewer.