Skip to content

Commit 2c9a601

Browse files
committed
FrogSimulation
1 parent fe7e702 commit 2c9a601

5 files changed

Lines changed: 179 additions & 11 deletions

File tree

.github/workflows/classroom.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Autograding Tests
2+
'on':
3+
- push
4+
- repository_dispatch
5+
permissions:
6+
checks: write
7+
actions: read
8+
contents: read
9+
jobs:
10+
run-autograding-tests:
11+
runs-on: ubuntu-latest
12+
if: github.actor != 'github-classroom[bot]'
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: parta
17+
id: parta
18+
uses: classroom-resources/autograding-command-grader@v1
19+
with:
20+
test-name: parta
21+
setup-command: ''
22+
command: gradle test --tests "SoundTest.partA"
23+
timeout: 10
24+
max-score: 1
25+
- name: partb
26+
id: partb
27+
uses: classroom-resources/autograding-command-grader@v1
28+
with:
29+
test-name: partb
30+
setup-command: ''
31+
command: gradle test --tests "SoundTest.partB"
32+
timeout: 10
33+
max-score: 1
34+
- name: Autograding Reporter
35+
uses: classroom-resources/autograding-grading-reporter@v1
36+
env:
37+
PARTA_RESULTS: "${{steps.partb.outputs.result}}"
38+
PARTB_RESULTS: "${{steps.partb.outputs.result}}"
39+
with:
40+
runners: parta,partb
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.APCSLowell;
2+
3+
public class FrogSimulation {
4+
private int goalDistance;
5+
private int maxHops;
6+
7+
public FrogSimulation(int dist, int numHops) {
8+
goalDistance = dist;
9+
maxHops = numHops;
10+
maxHopsHolder = numHops; // ignore this, it's used for testing
11+
}
12+
13+
// private int hopDistance()
14+
// implementation is below, but not important
15+
16+
public boolean simulate() {
17+
/* to be implemented in part (a) */
18+
19+
}
20+
21+
public double runSimulations(int num) {
22+
/* to be implemented in part (b) */
23+
24+
}
25+
26+
// ignore the code below this line
27+
// -------------------------------------------------------------------------------------
28+
private int[] hopValues;
29+
private int hopIndex = 0;
30+
31+
private int[][] hopValuesMatrix;
32+
private int row = 0;
33+
private int col = 0;
34+
35+
private int maxHopsHolder;
36+
private String part;
37+
38+
private int hopDistance() {
39+
if (this.part.equals("A")) {
40+
int value = 0;
41+
if (hopValues != null && hopIndex < hopValues.length) {
42+
value = hopValues[hopIndex];
43+
hopIndex++;
44+
}
45+
46+
return value;
47+
} else if (this.part.equals("B")) {
48+
int value = 0;
49+
if (hopValuesMatrix != null && row < hopValuesMatrix.length) {
50+
value = hopValuesMatrix[row][col];
51+
52+
col++;
53+
54+
if (col == hopValuesMatrix[row].length) {
55+
col = 0;
56+
row++;
57+
}
58+
}
59+
60+
return value;
61+
} else {
62+
return 0;
63+
}
64+
}
65+
66+
public void setPart(String letter) {
67+
this.part = letter;
68+
}
69+
70+
public void setHopValues(int[] hopValues) {
71+
this.hopValues = hopValues;
72+
this.hopIndex = 0;
73+
this.maxHops = maxHopsHolder;
74+
}
75+
76+
public void setMultipleHopValues(int[][] hopValuesMatrix) {
77+
this.hopValuesMatrix = hopValuesMatrix;
78+
this.row = 0;
79+
this.col = 0;
80+
}
81+
82+
}

lib/src/main/java/org/APCSLowell/Library.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.APCSLowell;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
public class FrogSimulationTest {
7+
@Test
8+
public void partA() {
9+
FrogSimulation test1 = new FrogSimulation(24, 5);
10+
test1.setPart("A");
11+
test1.setHopValues(new int[] { 5, 7, -2, 8, 6 });
12+
boolean res = test1.simulate();
13+
assertEquals(res, true);
14+
test1.setHopValues(new int[] { 6, 7, 6, 6 });
15+
res = test1.simulate();
16+
assertEquals(res, true);
17+
test1.setHopValues(new int[] { 6, -6, 31 });
18+
res = test1.simulate();
19+
assertEquals(res, true);
20+
test1.setHopValues(new int[] { 4, 2, -8 });
21+
res = test1.simulate();
22+
assertEquals(res, false);
23+
test1.setHopValues(new int[] { 5, 4, 2, 4, 3 });
24+
res = test1.simulate();
25+
assertEquals(res, false);
26+
test1.setHopValues(new int[] { 24, -7, -6, -6 });
27+
res = test1.simulate();
28+
assertEquals(res, true);
29+
test1 = new FrogSimulation(15, 3);
30+
test1.setPart("A");
31+
test1.setHopValues(new int[] { 6, 7, 11 });
32+
res = test1.simulate();
33+
assertEquals(res, true);
34+
}
35+
36+
@Test
37+
public void partB() {
38+
FrogSimulation test1 = new FrogSimulation(24, 5);
39+
test1.setPart("B");
40+
int[][] testMatrix = { { 5, 7, -2, 8, 6 },
41+
{ 6, 7, 6, 6 },
42+
{ 6, -6, 31 },
43+
{ 4, 2, -8 },
44+
{ 5, 4, 2, 4, 3 } };
45+
test1.setMultipleHopValues(testMatrix);
46+
assertEquals(test1.runSimulations(5), .6, .01);
47+
int[][] testMatrix2 = { { 5, 7, -2, 8, 6 },
48+
{ 5, 4, 2, 4, 3 } };
49+
test1.setMultipleHopValues(testMatrix2);
50+
assertEquals(test1.runSimulations(2), .5, .01);
51+
int[][] testMatrix3 = { { 5, 7, -2, 8, 6 },
52+
{ 6, 7, 6, 6 },
53+
{ 6, -6, 31 } };
54+
test1.setMultipleHopValues(testMatrix3);
55+
assertEquals(test1.runSimulations(3), 1.0, .01);
56+
}
57+
}

lib/src/test/java/org/APCSLowell/LibraryTest.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)