Skip to content

Commit

Permalink
working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Leiser authored and Kevin Leiser committed Jun 22, 2018
1 parent 9260b56 commit 325ecaf
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 185 deletions.
378 changes: 224 additions & 154 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/test/HW6/cs3500/animator/InteractiveTest/MockView.class
Binary file not shown.
2 changes: 1 addition & 1 deletion src/cs3500/animator/controller/InteractiveController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void action(GuiEventType type) {
@Override
public void change(GuiEventType type, int value) {
if (type.equals(GuiEventType.CHANGE_SPEED)) {

frameRate = value;
int delay = 1000 / frameRate;
timer.setDelay(delay);
} else {
Expand Down
42 changes: 21 additions & 21 deletions test/cs3500/animator/InteractiveTest/DummyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
import cs3500.animator.view.HybridView;

/**
*
* DummyController has basic outputs to prove correct functions are being called at right times.
*/
public class DummyController extends HybridController {

private Appendable output;

/**
* Constructor for the GUI controller. Reads data from model and tells the view what to print.
* Constructor for a mock controller. Reads data from model and tells the view what to print.
*
* @param model model to be used to get cs3500.animator.model.animation information.
* @param hybridView View to display cs3500.animator.model.animation in a GUI.
* @param frameRatePerSec frame rate at which the cs3500.animator.model.animation will run.
*/
public DummyController(IAnimationModel model, HybridView hybridView,
int frameRatePerSec, Appendable output) {
this.guiView = hybridView;
this.model = model;
this.frameRate = frameRatePerSec;
public DummyController(IAnimationModel model, HybridView hybridView, Appendable output) {
this.hybridView = hybridView;

if (model != null) {
this.model = model;
}

this.output = output;
setAsActionListener();
setAsChangeListener();
}

/**
Expand All @@ -36,7 +39,7 @@ public Appendable getOutput() {
return output;
}

public void setAsActionListener() {
public void setAsActionListener() {
hybridView.setActionListener(this);
}

Expand All @@ -48,18 +51,15 @@ public void setAsChangeListener() {
public void action(GuiEventType type) {
recentEvent = type;
if(type.equals(GuiEventType.START_STOP)) {
if (timer.isRunning()) {
try {
output.append("stopping");
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
output.append("starting");
} catch (IOException e) {
e.printStackTrace();
}
try {
output.append("stopping");
} catch (IOException e) {
e.printStackTrace();
}
try {
output.append("starting");
} catch (IOException e) {
e.printStackTrace();
}
} else if (type.equals(GuiEventType.RESTART)) {
try {
Expand Down
62 changes: 54 additions & 8 deletions test/cs3500/animator/InteractiveTest/InteractiveTests.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,75 @@
package cs3500.animator.InteractiveTest;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import java.awt.event.ActionEvent;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* Test class to test proper function calls are made across view and controller when events occur
* in gui.
*/
public class InteractiveTests {

/**
* things to test:
* start/stop
* restart
* loop
* speed
*/
private final int FPS_MIN = 1;
private final int FPS_MAX = 60;
private final int FPS_INIT = 30;

private DummyController mockController;
private MockView mockView;
private ActionEvent startStop;
private ActionEvent restart;
private ActionEvent loopToggle;
private ActionEvent export;
private ChangeEvent changeSpeed;
private StringBuilder controlOut;
private StringBuilder viewOut;

@Before
public void initialize() {

viewOut = new StringBuilder();
mockView = new MockView(viewOut);
startStop = new ActionEvent(mockView, ActionEvent.ACTION_FIRST, "start stop button");
restart = new ActionEvent(mockView, 1, "restart button");
loopToggle = new ActionEvent(mockView, 2, "toggle looping button");
export = new ActionEvent(mockView, 3, "export button");
controlOut = new StringBuilder();
mockController = new DummyController(null, mockView, controlOut );
}

@Test
public void restartTest() {
mockView.actionPerformed(restart);
assertEquals("restart button clicked\n", viewOut.toString());
}

@Test
public void startStopTest() {
mockView.actionPerformed(startStop);
assertEquals("start/stop button clicked\n", viewOut.toString());
}

@Test
public void setLoopToggleTest() {
mockView.actionPerformed(loopToggle);
assertEquals("looping toggle button clicked\n", viewOut.toString());
}

@Test
public void exportTest() {
mockView.actionPerformed(export);
assertEquals("export button clicked\n", viewOut.toString());
}

@Test
public void ChangeSpeedTest() {
JSlider slider = new JSlider(JSlider.HORIZONTAL, FPS_MIN, FPS_MAX, FPS_INIT);
changeSpeed = new ChangeEvent(slider);
slider.setValue(35);
mockView.stateChanged(changeSpeed);
assertEquals("Speed changed to 35\n", viewOut.toString());
}
}
2 changes: 1 addition & 1 deletion test/cs3500/animator/InteractiveTest/MockView.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void stateChanged(ChangeEvent changeEvent) {
int value = (int)source.getValue();
fireChange(IListener.GuiEventType.CHANGE_SPEED, value);
try {
out.append("Speed Changed to \n" + value);
out.append("Speed changed to " + value + "\n");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 325ecaf

Please sign in to comment.