public void FunctionAllArgs() { TestScaffold.TestLines( lines: new List <string>() { "import basic:array l:array \r\n" + "f:addarray := { \r\n" + " v:len := l:array.f:length(a:all) \r\n" + " v:sum := 0 \r\n" + " v:i := 0 \r\n" + " while (v:i < v:len) { \r\n" + " v:sum += a:all[v:i] \r\n" + " v:i += 1 \r\n" + " } \r\n" + " v:sum \r\n" + "} \r\n" + " \r\n" + "f:addarray(1, 2, 3, 4) \r\n" + "// returns 10" }, expected: new List <object>() { new InputVar("v:sum", 10.0) }); }
public void AppendVarTest() { TestScaffold.TestLinesOrderAndSequential( lines: new List <string>() { "f:import('basic:array','l:array');0.0", "v:basearr := (1,2,3,4) \r\n" + "v:val := 2 \r\n" + "v:arr := l:array.f:append(v:basearr, v:val)\r\n" + "l:array.f:length(v:arr)", "v:arr[0]", "v:arr[1]", "v:arr[2]", "v:arr[3]", "v:arr[4]", "v:val := 3 \r\n v:arr[4]" }, expected: new List <object>() { 0.0, 5, 1.0, 2.0, 3.0, 4.0, 2.0, 2.0 } ); }
public void InsertLastTest() { TestScaffold.TestLinesOrderAndSequential( lines: new List <string>() { "f:import('basic:array','l:array');0.0", "v:arr := l:array.f:insert((1, 2, 3, 4), 5, 4)\r\n" + "l:array.f:length(v:arr)", "v:arr[0]", "v:arr[1]", "v:arr[2]", "v:arr[3]", "v:arr[4]" }, expected: new List <object>() { 0.0, 5, 1.0, 2.0, 3.0, 4.0, 5.0 } ); }
public void AbsTest() { TestScaffold.TestLinesOrderAndSequential( lines: new List <string>() { "f:import('basic:math','l:math');0.0", "l:math.f:abs(-1.0)", "l:math.f:abs(-12.5)", "l:math.f:abs(c:i(-8))", "l:math.f:abs(1.0)", "l:math.f:abs(12.5)", "l:math.f:abs(c:i(8))" }, expected: new List <object>() { 0.0, 1.0, 12.5, 8.0, 1.0, 12.5, 8.0 } ); }
public void ClausenTest() { MathLibrary ml = new MathLibrary(); TestScaffold.TestLines( lines: new List <string>() { "import basic:math l:math;0.0", "l:math.f:clausen(-1.0)", "l:math.f:clausen(-1.0, 5.0)", "l:math.f:clausen(7.0, 3.0, 1.0)", "l:math.f:clausen(10, 15, 300)", "v:test := 15; v:a := 3; l:math.f:clausen(12.5, v:test, v:a)", }, expected: new List <object>() { 0.0, ml.Clausen(new double[] { -1.0 }), ml.Clausen(new double[] { -1.0, 5.0 }), ml.Clausen(new double[] { 7.0, 3.0, 1.0 }), ml.Clausen(new double[] { 10.0, 15.0, 300.0 }), ml.Clausen(new double[] { 12.5, 15.0, 3.0 }), } ); }
public void DefnPoint() { TestScaffold.TestLines( lines: new List <string>() { "defn d:point {\r\n" + " v:x := 0\r\n" + " v:y := 0\r\n" + " f:init := {\r\n" + " a:x a:y\r\n" + " v:x = a:x\r\n" + " v:y = a:y\r\n" + " }\r\n" + " f:array := { v:x, v:y }\r\n" + "}\r\n" + "\r\n" + "v:point1 := object anon d:point (5, 10)\r\n" + "v:point1.f:array()[0]", "v:point1.f:array()[1]" }, expected: new List <object>() { new InputVar("v:x", 5.0), new InputVar("v:y", 10.0) }); }
public void CycloidTest() { MathLibrary ml = new MathLibrary(); TestScaffold.TestLines( lines: new List <string>() { "import basic:math l:math;0.0", "l:math.f:cycloid(-1.0, 0.75)", "l:math.f:cycloid(-1.0, 5.0)", "l:math.f:cycloid(7.0, 3.0)", "l:math.f:cycloid(10, 15)", "v:test := 15; v:a := 3; l:math.f:cycloid(v:test, v:a)", }, expected: new List <object>() { 0.0, ml.Cycloid(-1.0, 0.75), ml.Cycloid(-1.0, 5.0), ml.Cycloid(7.0, 3.0), ml.Cycloid(10.0, 15.0), ml.Cycloid(15.0, 3.0) } ); }
public void IfElseStatement() { TestScaffold.TestLines( lines: new List <string>() { "if (1 == 2) { 10 } else { 300 }" }, expected: new List <object>() { 300.0 }); }
public void Comment() { TestScaffold.TestLines( lines: new List <string>() { "15 // 20" }, expected: new List <object>() { 15.0 }); }
public void BooleanExample() { TestScaffold.TestLines( lines: new List <string>() { "1 == 2" }, expected: new List <object>() { false }); }
public void StringCasts() { TestScaffold.TestLines( lines: new List <string>() { "c:d(\"13.5\") + 5" }, expected: new List <object>() { 18.5 }); }
public void DoubleByDefault() { TestScaffold.TestLines( lines: new List <string>() { "9 / 2 // 4.5" }, expected: new List <object>() { 4.5 }); }
public void VariablesAssignmentResult() { TestScaffold.TestLines( lines: new List <string>() { "v:apples := 10" }, expected: new List <object>() { new InputVar("v:apples", 10.0) }); }
public void StringNonStringAddition() { TestScaffold.TestLines( lines: new List <string>() { "v:pies := \"we have \" + 3" }, expected: new List <object>() { new InputVar("v:pies", "we have 3") }); }
public void Scopes() { TestScaffold.TestLines( lines: new List <string>() { "{ v:i := 100 }\r\n " + "{ v:i := 50 }" }, expected: new List <object>() { new InputVar("v:i", 50.0) }); }
public void Funcs() { TestScaffold.TestLines( lines: new List <string>() { "f:half := { a:0 / 2 }\r\n" + "f:half(10)" }, expected: new List <object>() { 5.0 }); }
public void StringExample() { TestScaffold.TestLines( lines: new List <string>() { "v:special := \"lobster ravioli\"\r\n" + "v:dessert := 'burnt sage ice cream'" }, expected: new List <object>() { new InputVar("v:dessert", "burnt sage ice cream") }); }
public void MathLibraryExample() { TestScaffold.TestLines( lines: new List <string>() { "import basic:math l:math\r\n" + "l:math.f:max(100,30,0)" }, expected: new List <object>() { 100.0 }); }
public void ArrayAccess() { TestScaffold.TestLines( lines: new List <string>() { "v:arr := (10, 20, 30)\r\n" + "v:arr[1]" }, expected: new List <object>() { 20.0 }); }
public void StringLibraryLength() { TestScaffold.TestLines( lines: new List <string>() { "import basic:string l:str\r\n" + "l:str.f:length(\"boathouse\")" }, expected: new List <object>() { 9 }); }
public void VariablesAssignmentChainResult() { TestScaffold.TestLines( lines: new List <string>() { "v:apples := 10\r\n" + "v:oranges := v:apples += 5" }, expected: new List <object>() { new InputVar("v:oranges", 15.0) }); }
public void NonScopes() { TestScaffold.TestLines( lines: new List <string>() { "( v:i := 100 )\r\n " + "( v:i += 10 )" }, expected: new List <object>() { new InputVar("v:i", 110.0) }); }
public void MultidimensionalArray() { TestScaffold.TestLines( lines: new List <string>() { "v:grid := ((0, 0, 1), (0, 0, 0), (0, 0, 0))\r\n" + "v:grid[0][2]" }, expected: new List <object>() { 1.0 }); }
public void Variables() { TestScaffold.TestLines( lines: new List <string>() { "v:treats := 1\r\n" + "v:treats = 2\r\n" + "v:treats + 1" }, expected: new List <object>() { 3.0 }); }
public void StringArrayCommaAnd() { TestScaffold.TestLines( lines: new List <string>() { "import basic:string l:str\r\n" + "v:groceries := ('cherries', 'nectarines', 'grapes')\r\n" + "l:str.f:commaand(v:groceries)" }, expected: new List <object>() { "cherries, nectarines, and grapes" }); }
public void IfStatementsReturn() { TestScaffold.TestLines( lines: new List <string>() { "v:pears := 3\r\n" + "v:tarts := if (v:pears > 1) { 10 }\r\n" + "v:tarts += if (v:pears > 100) { 30 }" }, expected: new List <object>() { new InputVar("v:tarts", 10.0) }); }
public void StringAddition() { TestScaffold.TestLines( lines: new List <string>() { "v:groceries := 'cherries' + ' nectarines'\r\n" + "v:groceries += ' grapes'\r\n" + "v:errand := 'go get ' + v:groceries" }, expected: new List <object>() { new InputVar("v:errand", "go get cherries nectarines grapes") }); }
public void LastTermReturned() { TestScaffold.TestLines( lines: new List <string>() { "1\r\n" + "2\r\n" + "3" }, expected: new List <object>() { 3.0 }); }
public void VariablesAssignments() { TestScaffold.TestLines( lines: new List <string>() { "v:snacks := 10\r\n" + "v:snacks + 5\r\n" + "v:snacks += 3\r\n" + "v:snacks + 0" }, expected: new List <object>() { 13.0 }); }
public void LibraryMethodTakeAllArgsTest() { TestScaffold.TestLinesOrderAndSequential( lines: new List <string>() { "f:import('basic:math','l:math')\r\n" + "f:mpow := { l:math.f:pow(a:all) * 2 }\r\n" + "f:mpow(10, 2)", }, expected: new List <object>() { 200.0, } ); }