-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSharpMath.Evaluation.Interpret tests (#151)
* Added Interpret Tests + Deterministic Builds * Fix build * Fix build 2 * Simplify stuff * Make Extensions.cs the top-level source file of CSharpMath * ?? Windows? * Update Build.yml * E * Update Build.yml * Try fix? * Update Build.yml * Detect dotnet msbuild * Update Directory.Build.props * Update Test.yml * Update Test.yml * Sleeping does nothing * Simplify * Update Test.yml * Update local build version * Update Test.yml
- Loading branch information
1 parent
cecc4b0
commit 0f81662
Showing
20 changed files
with
279 additions
and
320 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
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,26 @@ | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
namespace CSharpMath.EvaluationTests { | ||
public class InterpretTests { | ||
[Theory] | ||
[InlineData(@"", @"\color{red}\text{There is nothing to evaluate}")] | ||
[InlineData(@"1", @"\underline\mathrm{Input}\\1\\\\\underline\mathrm{Simplified}\\1\\\\\underline\mathrm{Value\ (100\ digits)}\\1")] | ||
[InlineData(@"1+", @"\color{red}\text{Missing right operand for +}")] | ||
[InlineData(@"1+2", @"\underline\mathrm{Input}\\1+2\\\\\underline\mathrm{Simplified}\\3\\\\\underline\mathrm{Value\ (100\ digits)}\\3")] | ||
[InlineData(@"1+\sqrt", @"\color{red}\text{Missing radicand}")] | ||
[InlineData(@"1+\sqrt2", @"\underline\mathrm{Input}\\1+\sqrt{2}\\\\\underline\mathrm{Simplified}\\1+\sqrt{2}\\\\\underline\mathrm{Value\ (100\ digits)}\\2.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573")] | ||
[InlineData(@"1+\sqrt{2x}", @"\underline\mathrm{Input}\\1+\sqrt{2\times x_{}}\\\\\underline\mathrm{Simplified}\\1+\sqrt{2\times x_{}}\\\\\underline\mathrm{Expanded}\\1+\sqrt{2\times x_{}}\\\\\underline\mathrm{Factorized}\\1+\sqrt{2\times x_{}}")] | ||
[InlineData(@"1+\sqrt{2xy}", @"\underline\mathrm{Input}\\1+\sqrt{2\times x_{}\times y_{}}\\\\\underline\mathrm{Simplified}\\1+\sqrt{2\times x_{}\times y_{}}\\\\\underline\mathrm{Expanded}\\1+\sqrt{2\times x_{}\times y_{}}\\\\\underline\mathrm{Factorized}\\1+\sqrt{2\times x_{}\times y_{}}")] | ||
[InlineData(@"=1+\sqrt{2xy}", @"\color{red}\text{Missing left side of equation}")] | ||
[InlineData(@"1+\sqrt{2xy}=", @"\color{red}\text{Missing right side of equation}")] | ||
[InlineData(@"1+\sqrt{2xy}=3", @"\underline\mathrm{Input}\\1+\sqrt{2\times x_{}\times y_{}}=3\\\\\underline\mathrm{Solutions}\\x_{}\in \left\{\frac{--\frac{4}{y_{}}}{2}\right\}\\y_{}\in \left\{\frac{4}{2\times x_{}}\right\}\\")] | ||
[InlineData(@"1=3", @"\underline\mathrm{Input}\\1=3\\\\\underline\mathrm{Result}\\\text{False}")] | ||
[InlineData(@"1=1", @"\underline\mathrm{Input}\\1=1\\\\\underline\mathrm{Result}\\\text{True}")] | ||
public void Interpret(string input, string expected) { | ||
var actual = Evaluation.Interpret(EvaluationTests.ParseLaTeX(input)); | ||
Assert.Equal(expected, actual); | ||
Assert.NotEmpty(EvaluationTests.ParseLaTeX(actual)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,62 +1,60 @@ | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
namespace CSharpMath { | ||
public partial class EvaluationTests { | ||
public class PredictTests { | ||
[Theory] | ||
[InlineData(1, 1, 1)] | ||
[InlineData(2, 2, 2)] | ||
[InlineData(1, 2, 3, 4)] | ||
[InlineData(3, 4, 5, 6)] | ||
[InlineData(1, 2, 3, 4, 5)] | ||
[InlineData(3, 4, 5, 6, 7)] | ||
[InlineData(1, 3, 5, 7)] | ||
[InlineData(8, 10, 12, 14)] | ||
[InlineData(1, 3, 5, 7, 9)] | ||
[InlineData(8, 10, 12, 14, 16)] | ||
[InlineData(1, 4, 7, 10)] | ||
[InlineData(1, 4, 7, 10, 13)] | ||
[InlineData(24, 31, 38, 45)] | ||
[InlineData(24, 31, 38, 45, 52)] | ||
[InlineData(17, 21, 25, 29)] | ||
[InlineData(17, 21, 25, 29, 33)] | ||
[InlineData(1, 1, 1, 1)] | ||
[InlineData(1, 1, 1, 1, 1)] | ||
[InlineData(1, 3, 1, 3, 1)] | ||
[InlineData(1, 3, 1, 3, 1, 3)] | ||
[InlineData(1, 2, 4, 8)] | ||
[InlineData(1, 2, 4, 8, 16)] | ||
[InlineData(1, 3, 9, 27)] | ||
[InlineData(1, 3, 9, 27, 81)] | ||
[InlineData(1, -2, 4, -8)] | ||
[InlineData(-1, 2, -4, 8)] | ||
[InlineData(30, 31, 40, 41, 50, 51)] | ||
[InlineData(61, 62, 63, 71, 72, 73, 81, 82)] | ||
[InlineData(2, 4, 8, 24, 48, 96, 288, 576, 1152)] | ||
[InlineData(0, 0, 0, 1, 0, 0, 0, 1, 0)] | ||
[InlineData(39, 34, 27, 22, 15, 10)] | ||
[InlineData(39, 34, 27, 22, 15, 10, 3)] | ||
[InlineData(31, 30, 22, 21, 13, 12)] | ||
[InlineData(31, 30, 22, 21, 13, 12, 4)] | ||
// Use int instead of double because https://github.com/xunit/xunit/issues/1670#issuecomment-373566797 | ||
public void Integer(params int[] input) { | ||
static void Test(System.Collections.Generic.IEnumerable<int> seq) => | ||
Assert.Equal(seq.Last(), Assert.IsType<double>(Evaluation.Predict(seq.Select(x => (double)x).SkipLast(1).ToArray())), 12); | ||
Test(input); | ||
Test(input.Reverse()); | ||
} | ||
[Theory] | ||
[InlineData(new int[0])] | ||
[InlineData(1)] | ||
[InlineData(1, 2)] | ||
[InlineData(2, 1)] | ||
[InlineData(1, 2, 1)] | ||
[InlineData(1, 2, 1, 3)] | ||
[InlineData(39, 34, 27, 22)] | ||
[InlineData(31, 30, 22, 21)] | ||
public void IntegerFail(params int[] input) => | ||
Assert.Null(Evaluation.Predict(input.Select(x => (double)x).ToArray())); | ||
namespace CSharpMath.EvaluationTests { | ||
public class PredictTests { | ||
[Theory] | ||
[InlineData(1, 1, 1)] | ||
[InlineData(2, 2, 2)] | ||
[InlineData(1, 2, 3, 4)] | ||
[InlineData(3, 4, 5, 6)] | ||
[InlineData(1, 2, 3, 4, 5)] | ||
[InlineData(3, 4, 5, 6, 7)] | ||
[InlineData(1, 3, 5, 7)] | ||
[InlineData(8, 10, 12, 14)] | ||
[InlineData(1, 3, 5, 7, 9)] | ||
[InlineData(8, 10, 12, 14, 16)] | ||
[InlineData(1, 4, 7, 10)] | ||
[InlineData(1, 4, 7, 10, 13)] | ||
[InlineData(24, 31, 38, 45)] | ||
[InlineData(24, 31, 38, 45, 52)] | ||
[InlineData(17, 21, 25, 29)] | ||
[InlineData(17, 21, 25, 29, 33)] | ||
[InlineData(1, 1, 1, 1)] | ||
[InlineData(1, 1, 1, 1, 1)] | ||
[InlineData(1, 3, 1, 3, 1)] | ||
[InlineData(1, 3, 1, 3, 1, 3)] | ||
[InlineData(1, 2, 4, 8)] | ||
[InlineData(1, 2, 4, 8, 16)] | ||
[InlineData(1, 3, 9, 27)] | ||
[InlineData(1, 3, 9, 27, 81)] | ||
[InlineData(1, -2, 4, -8)] | ||
[InlineData(-1, 2, -4, 8)] | ||
[InlineData(30, 31, 40, 41, 50, 51)] | ||
[InlineData(61, 62, 63, 71, 72, 73, 81, 82)] | ||
[InlineData(2, 4, 8, 24, 48, 96, 288, 576, 1152)] | ||
[InlineData(0, 0, 0, 1, 0, 0, 0, 1, 0)] | ||
[InlineData(39, 34, 27, 22, 15, 10)] | ||
[InlineData(39, 34, 27, 22, 15, 10, 3)] | ||
[InlineData(31, 30, 22, 21, 13, 12)] | ||
[InlineData(31, 30, 22, 21, 13, 12, 4)] | ||
// Use int instead of double because https://github.com/xunit/xunit/issues/1670#issuecomment-373566797 | ||
public void Integer(params int[] input) { | ||
static void Test(System.Collections.Generic.IEnumerable<int> seq) => | ||
Assert.Equal(seq.Last(), Assert.IsType<double>(Evaluation.Predict(seq.Select(x => (double)x).SkipLast(1).ToArray())), 12); | ||
Test(input); | ||
Test(input.Reverse()); | ||
} | ||
[Theory] | ||
[InlineData(new int[0])] | ||
[InlineData(1)] | ||
[InlineData(1, 2)] | ||
[InlineData(2, 1)] | ||
[InlineData(1, 2, 1)] | ||
[InlineData(1, 2, 1, 3)] | ||
[InlineData(39, 34, 27, 22)] | ||
[InlineData(31, 30, 22, 21)] | ||
public void IntegerFail(params int[] input) => | ||
Assert.Null(Evaluation.Predict(input.Select(x => (double)x).ToArray())); | ||
} | ||
} |
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
Oops, something went wrong.