Skip to content

Commit

Permalink
A few test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrcounts committed Apr 2, 2015
1 parent d1554e7 commit 516438f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 99 deletions.
167 changes: 83 additions & 84 deletions src/main/java/org/teachingextensions/logo/Turtle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,8 @@
*/
public class Turtle
{
/**
* Current types are: ExplodedTurtle, Turtle, Spider
*/
public enum Animals {
ExplodedTurtle, Turtle, Spider, Unicorn
}
private class Turner implements Saver<Double>
{
@Override
public Double save(Double save) throws SavingException
{
smallTurn(save);
return save;
}
}
private class Mover implements Saver<Double>
{
private final Point starting;
private LineSegment line = null;
public Mover(Point point)
{
this.starting = point;
}
@Override
public Double save(Double save) throws SavingException
{
moveWithoutAnimation(save);
if (line != null)
{
trail.remove(line);
}
line = new LineSegment(color, starting, new Point(getX(), getY()), width);
trail.add(line);
return save;
}
}
private class EmptyMover implements Saver<Double>
{
@Override
public Double save(Double save) throws SavingException
{
moveWithoutAnimation(save);
return save;
}
}
private static final double MAX_MOVE_AMOUNT = 5.0;
public static final int TEST_SPEED = Integer.MIN_VALUE;
private static final double MAX_MOVE_AMOUNT = 5.0;
private double x = 640 / 2;
private double y = 480 / 2;
private double angleInDegrees = 0;
Expand All @@ -77,7 +32,23 @@ public Double save(Double save) throws SavingException
private boolean penDown = true;
private boolean hidden;
private Animals animal;
//
public static double getDeltaY(double i, double angleInDegrees2)
{
return -i * Math.cos(Math.toRadians(angleInDegrees2));
}
public static double getDeltaX(double i, double angleInDegrees2)
{
return i * Math.sin(Math.toRadians(angleInDegrees2));
}
public static double angleCalculator(int x1, int y1, int x2, int y2)
{
int delta_x = x1 - x2;
int delta_y = y1 - y2;
double theta_radians = Math.atan2(delta_y, delta_x);
double degrees = Math.toDegrees(theta_radians);
double degreesWith0North = degrees - 90;
return degreesWith0North;
}
public BufferedImage getImage()
{
BufferedImage image = ComponentApprovalWriter.drawComponent(getPanel());
Expand Down Expand Up @@ -108,14 +79,26 @@ private Component getPanel()
}
return panel;
}
public void setPanel(TurtlePanel panel)
{
this.panel = panel;
}
public int getX()
{
return (int) x;
}
public void setX(Number x)
{
this.x = x.doubleValue();
}
public int getY()
{
return (int) y;
}
public void setY(Number y)
{
this.y = y.doubleValue();
}
public double getAngleInDegrees()
{
return angleInDegrees;
Expand All @@ -124,14 +107,6 @@ public void setAngleInDegrees(double angleInDegrees)
{
this.angleInDegrees = angleInDegrees;
}
public void setX(Number x)
{
this.x = x.doubleValue();
}
public void setY(Number y)
{
this.y = y.doubleValue();
}
public void turn(double amount)
{
double max = getTurnAmount(amount);
Expand Down Expand Up @@ -187,6 +162,10 @@ private long getDelay()
if (getSpeed() == TEST_SPEED) { return TEST_SPEED; }
return 100 / getSpeed();
}
public int getSpeed()
{
return speed;
}
public void setSpeed(int speed)
{
if (speed != TEST_SPEED)
Expand All @@ -199,10 +178,6 @@ public void setSpeed(int speed)
}
this.speed = speed;
}
public int getSpeed()
{
return speed;
}
public double getHeadingInDegrees()
{
return angleInDegrees;
Expand All @@ -218,26 +193,18 @@ private void moveWithoutAnimation(Double save)
x += getDeltaX(save, angleInDegrees);
y += getDeltaY(save, angleInDegrees);
}
public static double getDeltaY(double i, double angleInDegrees2)
{
return -i * Math.cos(Math.toRadians(angleInDegrees2));
}
public static double getDeltaX(double i, double angleInDegrees2)
{
return i * Math.sin(Math.toRadians(angleInDegrees2));
}
public LineSegment[] getTrail()
{
return trail.toArray(new LineSegment[trail.size()]);
}
public void setPenColor(Color color)
{
this.color = color;
}
public Color getPenColor()
{
return color;
}
public void setPenColor(Color color)
{
this.color = color;
}
public int getPenWidth()
{
return width;
Expand Down Expand Up @@ -301,19 +268,6 @@ public void moveSynchronized(int x, int y)
double distance = new Point(x, y).distance(getX(), getY());
move(distance);
}
public static double angleCalculator(int x1, int y1, int x2, int y2)
{
int delta_x = x1 - x2;
int delta_y = y1 - y2;
double theta_radians = Math.atan2(delta_y, delta_x);
double degrees = Math.toDegrees(theta_radians);
double degreesWith0North = degrees - 90;
return degreesWith0North;
}
public void setPanel(TurtlePanel panel)
{
this.panel = panel;
}
public void drawStar(int size)
{
for (int i = 1; i <= 5; i++)
Expand All @@ -326,4 +280,49 @@ public boolean isDead()
{
return this.animal == Animals.ExplodedTurtle;
}
/**
* Current types are: ExplodedTurtle, Turtle, Spider
*/
public enum Animals {
ExplodedTurtle, Turtle, Spider, Unicorn
}
private class Turner implements Saver<Double>
{
@Override
public Double save(Double save) throws SavingException
{
smallTurn(save);
return save;
}
}
private class Mover implements Saver<Double>
{
private final Point starting;
private LineSegment line = null;
public Mover(Point point)
{
this.starting = point;
}
@Override
public Double save(Double save) throws SavingException
{
moveWithoutAnimation(save);
if (line != null)
{
trail.remove(line);
}
line = new LineSegment(color, starting, new Point(getX(), getY()), width);
trail.add(line);
return save;
}
}
private class EmptyMover implements Saver<Double>
{
@Override
public Double save(Double save) throws SavingException
{
moveWithoutAnimation(save);
return save;
}
}
}
24 changes: 15 additions & 9 deletions src/main/java/org/teachingextensions/logo/TurtlePanel.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.teachingextensions.logo;

import org.teachingextensions.logo.Turtle.Animals;
import org.teachingextensions.windows.ProgramWindow;

import javax.swing.*;
import java.awt.*;
import java.awt.BasicStroke;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.net.URL;

@SuppressWarnings("serial")
import javax.swing.ImageIcon;

import org.teachingextensions.logo.Turtle.Animals;
import org.teachingextensions.windows.ProgramWindow;

public class TurtlePanel extends ProgramWindow
{
private Turtle turtle;
private Image image;
private Animals animal;
private static final long serialVersionUID = 3272676059303477850L;
private Turtle turtle;
private Image image;
private Animals animal;
public TurtlePanel()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.teachingextensions.logo.tests;

import junit.framework.TestCase;

import org.junit.Test;
import org.teachingextensions.approvals.lite.Approvals;
import org.teachingextensions.approvals.lite.reporters.ClipboardReporter;
import org.teachingextensions.approvals.lite.reporters.DiffReporter;
import org.teachingextensions.approvals.lite.reporters.UseReporter;
import org.teachingextensions.logo.Turtle;
import org.teachingextensions.logo.TurtlePanel;

@UseReporter({ClipboardReporter.class, DiffReporter.class})
public class TurtlePanelTest extends TestCase
public class TurtlePanelTest
{
@Test
public void testImageForBackground() throws Exception
{
Turtle turtle = TurtleUtils.getTurtle();
Expand All @@ -19,4 +20,10 @@ public void testImageForBackground() throws Exception
"http://teachingkidsprogramming.org/blog/wp-content/uploads/teachingKidsProgramming_logo_sm.png");
Approvals.verify(turtle.getImage());
}
// @Test
public void testNamedPanel()
{
TurtlePanel panel = new TurtlePanel("Turtle Bay");
Approvals.verify(panel);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions src/test/java/org/teachingextensions/logo/tests/TurtleTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.teachingextensions.logo.tests;

import java.awt.Color;

import junit.framework.TestCase;

import org.teachingextensions.approvals.lite.Approvals;
import org.teachingextensions.approvals.lite.reporters.DelayedClipboardReporter;
import org.teachingextensions.approvals.lite.reporters.DiffReporter;
Expand All @@ -13,6 +10,8 @@
import org.teachingextensions.logo.Turtle;
import org.teachingextensions.logo.Wheel;

import java.awt.*;

@UseReporter({DiffReporter.class, DelayedClipboardReporter.class})
public class TurtleTest extends TestCase
{
Expand Down Expand Up @@ -129,4 +128,10 @@ public String call(Integer speed)
}
});
}
public void testClear() throws Exception
{
Turtle turtle = TurtleUtils.getTurtle();
turtle.clear();
Approvals.verify(turtle.getImage());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 516438f

Please sign in to comment.