Testklassen passend einsortiert

This commit is contained in:
ngb 2022-06-19 22:22:28 +02:00
parent f736946a5f
commit 5df96815ea
10 changed files with 572 additions and 64 deletions

View File

@ -1,54 +0,0 @@
package schule.ngb.zm;
import schule.ngb.zm.turtle.Turtleebene;
public class TestTurtle extends Zeichenfenster {
public static void main(String[] args) {
new TestTurtle();
}
Turtleebene turtle;
public void einstellungen() {
turtle = new Turtleebene();
hinzu(turtle);
}
public void neck( int n, int s, Farbe f ) {
for( int i = 0; i < n; i++ ) {
turtle.vor(s);
turtle.rechts( 360.0 / n );
}
turtle.setFuellfarbe(f);
turtle.fuellen();
}
public void vorbereiten() {
turtle.setKonturDicke(2.5);
neck(7, 50, Farbe.HGGRUEN);
/*
turtle.vor(100);
turtle.links(135);
turtle.stiftHoch();
turtle.vor(100);
turtle.rechts();
turtle.stiftRunter();
turtle.setKonturFarbe(50, 190, 33);
turtle.vor(100);
turtle.links();
turtle.setKonturDicke(4);
//turtle.setKonturArt(Turtleebene.Turtle.GEPUNKTET);
turtle.vor(50);
*/
/*Turtleebene.Turtle t = turtle.neueTurtle();
t.setKonturDicke(1.5);
for( int i = 0; i < 360; i++ ) {
t.vor(1);
t.rechts(1);
}*/
}
}

View File

@ -0,0 +1,135 @@
package schule.ngb.zm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ColorTest {
@Test
void testEquals() {
Color c1 = new Color(254, 98, 12);
Color c2 = new Color(254, 98, 12);
assertNotSame(c1, c2);
assertEquals(c1, c2);
assertEquals(c1, c1);
c2 = new Color(c1);
assertNotSame(c1, c2);
assertEquals(c1, c2);
assertEquals(Color.YELLOW, java.awt.Color.YELLOW);
assertNotEquals(java.awt.Color.YELLOW, Color.YELLOW);
}
@Test
void construct() {
Color c;
// Empty color is white
c = new Color();
assertEquals(c, Color.BLACK);
// One arg is shade of gray
c = new Color(255);
assertEquals(c, Color.WHITE);
c = new Color(0);
assertEquals(c, Color.BLACK);
c = new Color(64);
assertEquals(c, Color.DARKGRAY);
c = new Color(192);
assertEquals(c, Color.LIGHTGRAY);
// RGB colors
c = new Color(0,0,0);
assertEquals(c, Color.BLACK);
c = new Color(255,0,0);
assertEquals(c, Color.RED);
c = new Color(0,255,0);
assertEquals(c, Color.GREEN);
c = new Color(0,0,255);
assertEquals(c, Color.BLUE);
// From java.awt.Color
c = new Color(java.awt.Color.YELLOW);
assertEquals(c, Color.YELLOW);
}
@Test
void getRGBColor() {
Color c1 = Color.getRGBColor(0xFFFF0000);
assertEquals(Color.RED, c1);
}
@Test
void getHSBColor() {
}
@Test
void getHSLColor() {
}
@Test
void parseHexcode() {
}
@Test
void morph() {
}
@Test
void RGBtoHSL() {
}
@Test
void HSLtoRGB() {
}
@Test
void testHSLtoRGB() {
}
@Test
void copy() {
}
@Test
void getRGBA() {
assertEquals(java.awt.Color.YELLOW.getRGB(), Color.YELLOW.getRGBA());
}
@Test
void getRed() {
}
@Test
void getGreen() {
}
@Test
void getBlue() {
}
@Test
void getAlpha() {
}
@Test
void getColor() {
assertEquals(java.awt.Color.YELLOW, Color.YELLOW.getJavaColor());
assertEquals(new java.awt.Color(255, 31, 124), new Color(255, 31, 124).getJavaColor());
}
@Test
void brighter() {
}
@Test
void testBrighter() {
}
@Test
void darker() {
}
@Test
void testDarker() {
}
}

View File

@ -0,0 +1,131 @@
package schule.ngb.zm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ConstantsTest {
@Test
void min() {
}
@Test
void max() {
assertEquals(5.0, Constants.max(5.0, 0.0), 0.000001);
assertEquals(5.0, Constants.max(5.0, 4.0), 0.000001);
assertEquals(5.0, Constants.max(5.0, 5.0), 0.000001);
assertEquals(100.0, Constants.max(100.0, -100.0), 0.000001);
assertEquals(0.0, Constants.max(0.0, 0.0), 0.000001);
assertEquals(5.0, Constants.max(new double[]{ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }), 0.000001);
assertEquals(5.0, Constants.max(new double[]{ 5.0, 5.0, 5.0, 5.0, 5.0 }), 0.000001);
assertEquals(5.0, Constants.max(new double[]{ 5.0 }), 0.000001);
assertThrows(IllegalArgumentException.class, () -> Constants.max(null));
assertThrows(IllegalArgumentException.class, () -> Constants.max(new double[]{}));
}
@Test
void abs() {
assertEquals(5.0, Constants.abs(5.0), 0.000001);
assertEquals(0.0, Constants.abs(0.0), 0.000001);
assertEquals(105.0, Constants.abs(-105.0), 0.000001);
}
@Test
void sign() {
assertEquals(1.0, Constants.sign(5.0), 0.000001);
assertEquals(0.0, Constants.sign(0.0), 0.000001);
assertEquals(-1.0, Constants.sign(-105.0), 0.000001);
}
@Test
void morph() {
assertEquals(0.0, Constants.interpolate(0.0, 100.0, 0.0), 0.000001);
assertEquals(10.0, Constants.interpolate(0.0, 100.0, 0.1), 0.000001);
assertEquals(50.0, Constants.interpolate(0.0, 100.0, 0.5), 0.000001);
assertEquals(100.0, Constants.interpolate(0.0, 100.0, 1.0), 0.000001);
assertEquals(-100.0, Constants.interpolate(-100.0, 100.0, 0.0), 0.000001);
assertEquals(0.0, Constants.interpolate(-100.0, 100.0, 0.5), 0.000001);
assertEquals(100.0, Constants.interpolate(-100.0, 100.0, 1.0), 0.000001);
}
@Test
void limit() {
assertEquals(4, Constants.limit(4, 1, 5));
assertEquals(1, Constants.limit(0, 1, 5));
assertEquals(5, Constants.limit(6, 1, 5));
assertEquals(1, Constants.limit(-6, 1, 5));
assertEquals(-6, Constants.limit(-6, -10, 5));
assertEquals(-10, Constants.limit(-15, -10, 5));
assertEquals(-10, Constants.limit(-10, -10, 5));
assertEquals(4.0, Constants.limit(4, 1, 5), 0.000001);
assertEquals(1.3, Constants.limit(0, 1.3, 5), 0.000001);
assertEquals(5.0, Constants.limit(6, 1, 5), 0.000001);
assertEquals(1.2, Constants.limit(-6, 1.2, 5), 0.000001);
assertEquals(-6.0, Constants.limit(-6, -10, 5), 0.000001);
assertEquals(-10.0, Constants.limit(-15, -10, 5), 0.000001);
assertEquals(-10.3, Constants.limit(-10.3, -10.3, 5), 0.000001);
}
@Test
void b() {
assertTrue(Constants.getBool(true));
assertFalse(Constants.getBool(false));
assertTrue(Constants.getBool(1));
assertFalse(Constants.getBool(0));
assertTrue(Constants.getBool(4.0));
assertFalse(Constants.getBool(0.0));
assertTrue(Constants.getBool(4.0f));
assertFalse(Constants.getBool(0.0f));
assertTrue(Constants.getBool(4L));
assertFalse(Constants.getBool(0L));
assertTrue(Constants.getBool("true"));
assertTrue(Constants.getBool("True"));
assertFalse(Constants.getBool("1"));
assertFalse(Constants.getBool("false"));
assertFalse(Constants.getBool("yes"));
assertFalse(Constants.getBool("no"));
}
@Test
void randomBool() {
float t = 0f, f = 0f;
for( int i = 0; i < 100000; i++ ) {
if( Constants.randomBool() ) {
t++;
} else {
f++;
}
}
assertEquals(.5f, Math.abs(t/(t+f)), .01f);
t = 0f;
f = 0f;
for( int i = 0; i < 100000; i++ ) {
if( Constants.randomBool(.2) ) {
t++;
} else {
f++;
}
}
assertEquals(.2f, Math.abs(t/(t+f)), .01f);
t = 0f;
f = 0f;
for( int i = 0; i < 100000; i++ ) {
if( Constants.randomBool(80) ) {
t++;
} else {
f++;
}
}
assertEquals(.8f, Math.abs(t/(t+f)), .01f);
}
}

View File

@ -0,0 +1,48 @@
package schule.ngb.zm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static schule.ngb.zm.Options.Direction.*;
class OptionsTest {
@Test
void testDirections() {
assertTrue(NORTH.in(NORTH));
assertTrue(NORTH.in(NORTHEAST));
assertTrue(EAST.in(NORTHEAST));
assertTrue(NORTH.in(NORTHWEST));
assertTrue(WEST.in(NORTHWEST));
assertFalse(NORTH.in(SOUTH));
assertFalse(NORTH.in(EAST));
assertFalse(NORTH.in(WEST));
assertFalse(NORTH.in(SOUTHWEST));
assertFalse(NORTH.in(SOUTHEAST));
assertFalse(NORTHEAST.in(NORTH));
assertFalse(NORTHEAST.in(SOUTH));
assertFalse(NORTHEAST.in(NORTHWEST));
assertTrue(NORTHEAST.in(NORTHEAST));
assertTrue(SOUTH.contains(SOUTH));
assertFalse(SOUTH.contains(NORTH));
assertFalse(SOUTH.contains(EAST));
assertFalse(SOUTH.contains(WEST));
assertFalse(SOUTH.contains(NORTHWEST));
assertFalse(SOUTH.contains(SOUTHWEST));
assertFalse(SOUTH.contains(SOUTHEAST));
assertTrue(SOUTHEAST.contains(SOUTH));
assertTrue(SOUTHEAST.contains(EAST));
assertTrue(SOUTHWEST.contains(SOUTH));
assertTrue(SOUTHWEST.contains(WEST));
assertFalse(SOUTHWEST.contains(NORTH));
assertFalse(SOUTHWEST.contains(SOUTHEAST));
assertTrue(SOUTHWEST.contains(SOUTHWEST));
assertFalse(SOUTHWEST.contains(EAST));
assertFalse(SOUTHWEST.contains(NORTHWEST));
}
}

View File

@ -90,8 +90,8 @@ public class TestAttraction extends Zeichenmaschine {
Vector acceleration( Vector a, Vector b, double ma, double mb ) {
Vector acc = Vector.sub(a, b);
double draw = (G*ma*mb)/acc.lenSq();
acc.setLen(draw*delta);
double draw = (G*ma*mb)/acc.lengthSq();
acc.setLength(draw*delta);
acc.limit(3, 30);
return acc;
}

View File

@ -42,14 +42,14 @@ public class TestColor {
public void parseColors() {
Color c;
c = Color.parseRGB(0x00FF00FF);
c = Color.getRGBColor(0x00FF00FF);
assertEquals(0x00FF00FF, c.getRGBA());
assertEquals(255, c.getRed());
assertEquals(0, c.getGreen());
assertEquals(255, c.getBlue());
assertEquals(0, c.getAlpha());
c = Color.parseRGB(0x33FF3333);
c = Color.getRGBColor(0x33FF3333);
assertEquals(0x33FF3333, c.getRGBA());
assertEquals(255, c.getRed());
assertEquals(51, c.getGreen());

View File

@ -0,0 +1,46 @@
package schule.ngb.zm;
import schule.ngb.zm.shapes.*;
import java.awt.geom.Point2D;
public class TestInput extends Zeichenmaschine {
public static void main( String[] args ) {
new TestInput();
}
private Text text;
@Override
public void setup() {
//setFramesPerSecond(5);
shapes.add(new Point(200, 200));
shapes.add(new Point(200, 200));
shapes.getShape(0).setFillColor(GREEN);
shapes.getShape(1).setFillColor(PINK);
text = new Text(10, 42, "");
text.setFontsize(32);
text.setAnchor(NORTHWEST);
shapes.add(text);
}
@Override
public void update( double delta ) {
shapes.getShape(0).moveTo(mouseX, mouseY);
shapes.getShape(1).moveTo(pmouseX, pmouseY);
}
@Override
public void draw() {
drawing.line(pmouseX, pmouseY, mouseX, mouseY);
}
public void keyPressed() {
text.setText(""+key);
}
}

View File

@ -19,6 +19,14 @@ public class TestShapes extends Zeichenmaschine {
public void setup() {
setSize(400, 400);
//createShapes();
//add(new Triangle(200, 150, 150, 250, 250, 250));
add(new Rectangle(200, 200, 200, 100));
shapes.getShape(0).setAnchor(CENTER);
}
public void createShapes() {
add(new Rectangle(20, 10, 40, 20));
add(new Ellipse(40, 50, 40, 20));
add(new Circle(40, 80, 10));
@ -55,13 +63,15 @@ public class TestShapes extends Zeichenmaschine {
@Override
public void update( double delta ) {
//shapes.getShape(Triangle.class).rotate(2);
shapes.getShape(0).rotate(200, 250,2);
}
@Override
public void mouseClicked() {
for( Shape s : shapes.getShapes() ) {
randomizeShape(s);
s.move(10, 10);
//s.move(10, 10);
}
}

View File

@ -96,11 +96,11 @@ public class TestVector {
assertEquals(-75, vec2.x, 0.0001);
assertEquals(-150, vec2.y, 0.0001);
assertEquals(100, vec1.set(100,0).len(), 0.0001);
assertEquals(10000, vec1.lenSq(), 0.0001);
assertEquals(Math.sqrt(50*50 + 60*60), vec1.set(50,60).len(), 0.0001);
assertEquals(1.0, vec1.set(100,0).normalize().len(), 0.0001);
assertEquals(1.0, Vector.random().normalize().len(), 0.0001);
assertEquals(100, vec1.set(100,0).length(), 0.0001);
assertEquals(10000, vec1.lengthSq(), 0.0001);
assertEquals(Math.sqrt(50*50 + 60*60), vec1.set(50,60).length(), 0.0001);
assertEquals(1.0, vec1.set(100,0).normalize().length(), 0.0001);
assertEquals(1.0, Vector.random().normalize().length(), 0.0001);
}

View File

@ -0,0 +1,192 @@
package schule.ngb.zm;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class VectorTest {
@Test
void setLength() {
Vector vec = new Vector(2.0, 5.4);
Vector vec2 = Vector.setLength(vec, 10);
assertEquals(10.0, vec2.length(), 0.00001);
Vector vec3 = Vector.setLength(vec, -10);
assertEquals(10.0, vec3.length(), 0.00001);
}
@Test
void normalize() {
Vector vec = new Vector(4.0, 3.0);
assertEquals(5.0, vec.length(), 0.00001);
Vector vec2 = vec.normalize();
assertSame(vec, vec2);
assertEquals(1.0, vec.length(), 0.00001);
}
@Test
void add() {
}
@Test
void sub() {
}
@Test
void scale() {
Vector vec = new Vector(4.0, 3.0);
assertEquals(5.0, vec.length(), 0.00001);
Vector vec2 = vec.scale(10.0);
assertSame(vec, vec2);
assertEquals(50.0, vec.length(), 0.00001);
vec2.scale(-10.0);
assertEquals(500.0, vec.length(), 0.00001);
assertEquals(-400.0, vec.x, 0.00001);
assertEquals(-300.0, vec.y, 0.00001);
}
@Test
void div() {
}
@Test
void dist() {
}
@Test
void dot() {
}
@Test
void cross() {
}
@Test
void rotate() {
}
@Test
void morph() {
}
@Test
void copy() {
}
@Test
void set() {
}
@Test
void testSet() {
}
@Test
void testSet1() {
}
@Test
void setX() {
}
@Test
void setY() {
}
@Test
void getPunkt() {
}
@Test
void len() {
Vector vec = new Vector(4.0, 3.0);
assertEquals(5.0, vec.length(), 0.00001);
vec = new Vector(1.0, 0.0);
assertEquals(1.0, vec.length(), 0.00001);
}
@Test
void lenSq() {
Vector vec = new Vector(4.0, 3.0);
assertEquals(25.0, vec.lengthSq(), 0.00001);
vec = new Vector(1.0, 0.0);
assertEquals(1.0, vec.lengthSq(), 0.00001);
}
@Test
void setLen() {
Vector vec = new Vector(2.0, 5.4);
Vector vec2 = vec.setLength(10);
assertEquals(10.0, vec.length(), 0.00001);
assertSame(vec, vec2);
vec.setLength(-10);
assertEquals(10.0, vec.length(), 0.00001);
}
@Test
void testNormalize() {
}
@Test
void testAdd() {
}
@Test
void testAdd1() {
}
@Test
void testSub() {
}
@Test
void testSub1() {
}
@Test
void testScale() {
}
@Test
void testDiv() {
}
@Test
void testDist() {
}
@Test
void testDot() {
}
@Test
void testDot1() {
}
@Test
void testCross() {
}
@Test
void limit() {
}
@Test
void testLimit() {
}
@Test
void angle() {
}
@Test
void testRotate() {
}
@Test
void testMorph() {
}
}