Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/02/19 13:55:49 (6 years ago)
Author:
gkronber
Message:

#2994: slightly changed calculation of integer powers for intervals and added unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/Tests/AutoDiffTest.cs

    r16738 r16744  
    107107
    108108      {
     109        // Interval tests
     110        var intervals = new Dictionary<string, Interval>();
     111        intervals.Add("x", new Interval(-2.0, 3.0));
     112        intervals.Add("p", new Interval(1.0, 2.0));
     113        intervals.Add("n", new Interval(-2.0, -1.0));
     114
     115        AssertInterval("10*x", intervals, -20, 30);
     116        AssertInterval("sqr(p)", intervals, 1, 4);
     117        AssertInterval("sqr(n)", intervals, 1, 4);
     118        AssertInterval("sqr(x)", intervals, 0, 9);
     119
     120        AssertInterval("cube(p)", intervals, 1, 8);
     121        AssertInterval("cube(n)", intervals, -8, -1);
     122        AssertInterval("cube(x)", intervals, -8, 27);
     123      }
     124
     125      {
    109126        // interval eval and auto-diff
    110127        var parser = new InfixExpressionParser();
     
    226243
    227244    }
     245
     246    private void AssertInterval(string expression, Dictionary<string, Interval> intervals, double expectedLow, double expectedHigh) {
     247      var parser = new InfixExpressionParser();
     248      var t = parser.Parse(expression);
     249      var evaluator = new IntervalEvaluator();
     250      var result = evaluator.Evaluate(t, intervals);
     251      Assert.AreEqual(expectedLow, result.LowerBound);
     252      Assert.AreEqual(expectedHigh, result.UpperBound);
     253    }
    228254  }
    229255}
Note: See TracChangeset for help on using the changeset viewer.