Skip to content

Instantly share code, notes, and snippets.

@Test
public void testMultiDigits() {
testResult("123", new Double(123));
}
@Test
public void testFractionalDecimal() {
testResult("123.456", new Double(123.456));
}
@Test
public void testFunctionWithRecursion() {
testResult(
"fakult(a) {" +
" if (a>1) {" +
" a * fakult(a-1)" +
" } else {" +
" 1" +
" }"+
"}" +
@timaschew
timaschew / ParserTests.java
Created January 7, 2011 00:00
Tests für Boolsche Ausdrücke, IfElse, While, Funktionen mit/ohne Parameter, rekursive Funktionen
@Test
public void testBooleanValues() {
testResult("true", true);
testResult("false", false);
testResult("x=true y=false x", true);
testResult("x=true y=false y", false);
}
@Test
public void testResult(String string, Double expected) {
testResult(string, new Value(expected));
}
public void testResult(String string, Boolean expected) {
testResult(string, new Value(expected), Type.BOOLEAN);
}
private final static String CLASS_NAME = "MyGeneratedClass";
private static Integer classCounter = new Integer(1);
@timaschew
timaschew / CompilerTests.java
Created February 23, 2011 02:35
nur funktionen
/*
Schema für parameter und rückgabewert-typen:
<TYPE>:<NAME>
Bsp: Parameter= double:a
Bsp: Funktion= boolean:equal(double:a double:b) {...}
Die Funktionen haben als Default double als Rückgabetyp, falls dieser nicht angegeben ist
*/
@Test
public void testSimpleFunction() {
@Test
public void testDigits() {
testResult("5", new Double(5));
testResult("123", new Double(123));
testResult("123.456", new Double(123.456));
}
@Test
public void testBooleanValues() {
testResult("true", true);
@timaschew
timaschew / ackermann
Created February 24, 2011 01:35
ackermann.class
// Compiled from MyGeneratedClass1.java (version 1.1 : 45.3, super bit)
public class MyGeneratedClass1 {
// Method descriptor #8 ()V
// Stack: 1, Locals: 1
public MyGeneratedClass1();
0 aload_0 [this]
1 invokespecial java.lang.Object() [10]
4 return
Local variable table:
@timaschew
timaschew / InteractiveGnuPlot.java
Created July 12, 2011 17:30
Using library JavaPlot for interactive rotating a Gnuplot in a JPanel
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import com.panayotis.gnuplot.JavaPlot;
import com.panayotis.gnuplot.swing.JPlot;
// include JavaPlot.jar from this site to your classpath
// http://gnujavaplot.sourceforge.net/JavaPlot/About.html
final EditingModalGraphMouse<Number,Number> graphMouse =
new EditingModalGraphMouse<Number,Number>(vv.getRenderContext(), vertexFactory, edgeFactory, 1,1);
graphMouse.setZoomAtMouse(false);
// the EditingGraphMouse will pass mouse event coordinates to the
// vertexLocations function to set the locations of the vertices as
// they are created
// graphMouse.setVertexLocations(vertexLocations);
vv.setGraphMouse(graphMouse);
@timaschew
timaschew / 3D_Rendering_Snippets.java
Created August 6, 2011 15:20
3D Animation with Java 2D API
public class Point3D {
public double x;
public double y;
public double z;
public Point3D(double xPos, double yPos, double zPos) {
this.x = xPos;
this.y = yPos;
this.z = zPos;
}