/* --------------------------------------------------------- * * __________ D E L T A S C R I P T * * (_________() * * / === / - A fast, dynamic scripting language * * | == | - Version 4.13.11.0 * * / === / - Developed by Adam R. Nelson * * | = = | - 2011-2013 * * / === / - Distributed under GNU LGPL v3 * * (________() - http://github.com/ar-nelson/deltascript * * * * --------------------------------------------------------- */ package com.sector91.delta.script.test; import static org.junit.Assert.*; import java.io.*; import com.sector91.delta.script.*; import com.sector91.delta.script.objects.DS_Scope; import com.sector91.delta.script.objects.DS_Tag; import com.sector91.delta.script.test.util.DeltaScriptTest; import org.junit.Test; public class StandardLibraryTest extends DeltaScriptTest { @Test public void testStandardLibraryAvailable() { assertEval("$StdLib", DeltaScript.STDLIB); } @Test public void testMathFunctions() { assertEval("..sin(91)", Math.sin(91)); assertEval("..cos(91)", Math.cos(91)); assertEval("..tan(91)", Math.tan(91)); assertEval("..sin(91.0)", Math.sin(91)); assertEval("..cos(91.0)", Math.cos(91)); assertEval("..tan(91.0)", Math.tan(91)); assertEval("..sgn(91.0)", 1); assertEval("..sgn(0)", 0); assertEval("..sgn(-91)", -1); } @Test public void testMinAndMax() { assertEval("..min(1, 2)", 1); assertEval("..max(1, 2)", 2); assertEval("..min(\"alligator\", \"buffalo\", \"rhinocerous\")", "alligator"); assertEval("..max(\"alligator\", \"buffalo\", \"rhinocerous\")", "rhinocerous"); } @Test public void testLoadFile() { try { File temp = File.createTempFile("test", ".ds"); temp.deleteOnExit(); BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write("func f(x); x*2; xf"); out.close(); String filename = temp.getCanonicalPath().replace("\\", "\\\\"); DS_Scope scope = context.createScope(); eval("loaded = ..load(\"" + filename + "\")", scope); assertEval("loaded.f(3)", integer(6), scope); } catch (IOException ex) { fail("Could not create temporary file for test: "+ex.getMessage()); } } @Test public void testMiscFunctions() { DS_Scope scope = context.createScope(); eval("..time", scope); eval("..print(\"Testing print method\")", scope); eval("..printErr(\"Testing printErr method\")", scope); assertEval("..hash('tag)", integer(DS_Tag.tag("tag").hashCode())); assertEval("..count(1,2,3)", integer(3)); } // FIXME: Determinant algorithm is wrong; fix and uncomment it. /*@Test public void testDeterminant() { assertEval("..det2(1, 2, 3, 4)", integer(-2)); assertEval("..det(<55, 71, -10>, <43, -91, 2>, <0, 7, 21>)", integer(-172998)); assertEval("..det(<1, 0, 0, 0>, <0, 2, 0, 0>, <0, 0, 3, 0>, <0, 0, 0, 4>)", integer(24)); assertEval("..det(<1, 2, 3, 4>, <4, 3, 2, 1>, <1, 2, 3, 4>, <4, 3, 2, 1>)", integer(0)); }*/ }