Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Removed trancendental functions
Browse files Browse the repository at this point in the history
Additional testing options
  • Loading branch information
tevador committed Jun 20, 2018
1 parent bf01e18 commit 7d444a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
23 changes: 21 additions & 2 deletions src/Tevador.RandomJS.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static int Main(string[] args)
bool help = false;
Uri runnerUri = new Uri("http://localhost:18111");
bool debug = false;
string outfile = null;

ProgramOptions customOptions = new ProgramOptions();
customOptions.Initialize();
Expand Down Expand Up @@ -132,7 +133,8 @@ static int Main(string[] args)
.Add("evalTestWeightRuntime=", (double d) => evalTestWeightRuntime = d)
.Add("help|h", s => help = true)
.Add("runnerUri=", s => runnerUri = new Uri(s))
.Add("debug", s => debug = true);
.Add("debug", s => debug = true)
.Add("outfile=", s => outfile = s);


foreach (var prop in typeof(ProgramOptions).GetProperties())
Expand Down Expand Up @@ -213,7 +215,24 @@ static int Main(string[] args)
return 1;
}*/

var stats = MakeStats(threads, count, timeout, seed, useCustomOptions ? customOptions : ProgramOptions.FromXml(), objective, evalTest, runnerUri);
var options = useCustomOptions ? customOptions : ProgramOptions.FromXml();

if (count == 1 && outfile != null && outfile.Length == 64 && outfile.All(c => "0123456789abcdef".Contains(c)))
{
var factory = new ProgramFactory(options);
var pr = factory.GenProgram(BinaryUtils.StringToByteArray(outfile));
using (var file = System.IO.File.CreateText(outfile + ".js"))
pr.WriteTo(file);

var runner = Run.ProgramRunnerBase.FromUri(runnerUri);
runner.WriteProgram(pr);
var ri = runner.ExecuteProgram();
Console.WriteLine(ri.Output);
Console.WriteLine($"Success = {ri.Success}");
return 0;
}

var stats = MakeStats(threads, count, timeout, seed, options, objective, evalTest, runnerUri);

if (objective)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tevador.RandomJS/Operators/UnaryOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class UnaryOperator : Operator
public readonly static UnaryOperator Plus = new UnaryOperator("+");
public readonly static UnaryOperator Typeof = new UnaryOperator("typeof ");
public readonly static UnaryOperator Minus = new UnaryOperator("-", OperatorRequirement.NumericOnly);
public readonly static UnaryOperator Sqrt = new UnaryOperator("Math.sqrt", OperatorRequirement.NumericOnly | OperatorRequirement.FunctionCall | OperatorRequirement.LimitedPrecision | OperatorRequirement.RhsNonnegative);
public readonly static UnaryOperator Sqrt = new UnaryOperator("Math.sqrt", OperatorRequirement.NumericOnly | OperatorRequirement.FunctionCall | OperatorRequirement.RhsNonnegative);
public readonly static UnaryOperator Cbrt = new UnaryOperator("Math.cbrt", OperatorRequirement.NumericOnly | OperatorRequirement.FunctionCall | OperatorRequirement.LimitedPrecision);
public readonly static UnaryOperator Abs = new UnaryOperator("Math.abs", OperatorRequirement.NumericOnly | OperatorRequirement.FunctionCall);
public readonly static UnaryOperator Ceil = new UnaryOperator("Math.ceil", OperatorRequirement.NumericOnly | OperatorRequirement.FunctionCall);
Expand Down
14 changes: 7 additions & 7 deletions src/Tevador.RandomJS/ProgramOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
<item type="Typeof" weight="2" /> <!-- OPERATOR typeof -->
<item type="Minus" weight="4" /> <!-- OPERATOR - (unary) -->
<item type="Not" weight="4" /> <!-- OPERATOR ! -->
<item type="Sqrt" weight="1" /> <!-- FUNCTION Math.sqrt -->
<item type="Exp" weight="1" /> <!-- FUNCTION Math.exp -->
<item type="Log" weight="1" /> <!-- FUNCTION Math.log -->
<item type="Sin" weight="1" /> <!-- FUNCTION Math.sin -->
<item type="Cos" weight="1" /> <!-- FUNCTION Math.cos -->
<item type="Atan" weight="1" /> <!-- FUNCTION Math.atan -->
<item type="Sqrt" weight="3" /> <!-- FUNCTION Math.sqrt -->
<item type="Exp" weight="0" /> <!-- FUNCTION Math.exp -->
<item type="Log" weight="0" /> <!-- FUNCTION Math.log -->
<item type="Sin" weight="0" /> <!-- FUNCTION Math.sin -->
<item type="Cos" weight="0" /> <!-- FUNCTION Math.cos -->
<item type="Atan" weight="0" /> <!-- FUNCTION Math.atan -->
<item type="Floor" weight="1" /> <!-- FUNCTION Math.floor -->
<item type="Ceil" weight="1" /> <!-- FUNCTION Math.ceil -->
<item type="Abs" weight="1" /> <!-- FUNCTION Math.abs -->
<item type="Trunc" weight="1" /> <!-- FUNCTION Math.trunc -->
<item type="Cbrt" weight="1" /> <!-- FUNCTION Math.cbrt -->
<item type="Cbrt" weight="0" /> <!-- FUNCTION Math.cbrt -->
</UnaryOperators>
<BinaryOperators>
<item type="Add" weight="8" /> <!-- OPERATOR + -->
Expand Down

0 comments on commit 7d444a0

Please sign in to comment.