-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from prekel/develop
Develop
- Loading branch information
Showing
40 changed files
with
1,891 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MyExpression.Core.Tests | ||
{ | ||
[TestFixture] | ||
public class CodeDomEvalTests | ||
{ | ||
[Test] | ||
public void RandomSinCos() | ||
{ | ||
Func<double, double> evalsin = new CodeDomEval("Math.Sin(x)").Calculate; | ||
double sin(double x) => Math.Sin(x); | ||
Func<double, double> evalcos = new CodeDomEval("Math.Cos(x)").Calculate; | ||
double cos(double x) => Math.Cos(x); | ||
var r = new MyRandom(); | ||
for (var i = 0; i < 100; i++) | ||
{ | ||
var x = r.Next(100) * r.NextDouble(); | ||
Assert.AreEqual(sin(x), evalsin(x)); | ||
Assert.AreEqual(cos(x), evalcos(x)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Random() | ||
{ | ||
Func<double, double> f1 = new CodeDomEval("Math.Sin(x)*1/x*4383+2143/1414+141-1.2*23*x*Math.Abs(x*Math.Sin(x))").Calculate; | ||
double f(double x) => Math.Sin(x) * 1 / x * 4383 + 2143 / 1414 + 141 - 1.2 * 23 * x * Math.Abs(x * Math.Sin(x)); | ||
var r = new MyRandom(); | ||
for (var i = 0; i < 1000; i++) | ||
{ | ||
var x = r.Next(100) * r.NextDouble(); | ||
Assert.AreEqual(f(x), f1(x), 1e-8); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2018 Vladislav Prekel | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace MyExpression.Core.Tests | ||
{ | ||
[TestFixture] | ||
public class OpenCloseIntervalTests | ||
{ | ||
[Test] | ||
public void Ctor1() | ||
{ | ||
var ra = new MyRandom(); | ||
var a = ra.NextDouble() * ra.Next() * ra.NextSign(); | ||
var b = ra.NextDouble() * ra.Next() * ra.NextSign(); | ||
var l = Math.Min(a, b); | ||
var r = Math.Max(a, b); | ||
|
||
var iw = new OpenCloseInterval(l, r); | ||
Assert.AreEqual(l, iw.Left); | ||
Assert.AreEqual(r, iw.Right); | ||
Assert.IsFalse(iw.IsLeftOpen); | ||
Assert.IsFalse(iw.IsRightOpen); | ||
} | ||
|
||
[Test] | ||
public void Ctor2() | ||
{ | ||
var ra = new MyRandom(); | ||
var a = ra.NextDouble() * ra.Next() * ra.NextSign(); | ||
var b = ra.NextDouble() * ra.Next() * ra.NextSign(); | ||
var l = Math.Min(a, b); | ||
var r = Math.Min(a, b); | ||
var lo = ra.NextBool(); | ||
var ro = ra.NextBool(); | ||
|
||
var iw = new OpenCloseInterval(l, lo, r, ro); | ||
Assert.AreEqual(l, iw.Left); | ||
Assert.AreEqual(r, iw.Right); | ||
Assert.AreEqual(lo, iw.IsLeftOpen); | ||
Assert.AreEqual(ro, iw.IsRightOpen); | ||
} | ||
} | ||
} |
Oops, something went wrong.