Skip to content

Commit

Permalink
Merge pull request #11 from jspam/005-42
Browse files Browse the repository at this point in the history
Add tests by group FortyTwo
  • Loading branch information
jspam committed Nov 9, 2014
2 parents 7a4b9b4 + eb37e09 commit 5376524
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 0 deletions.
5 changes: 5 additions & 0 deletions neg/negative1.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
public int getZero(int) {
return = 0;
}
}
22 changes: 22 additions & 0 deletions neg/negative2.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

class Fibonacci {
public int recursive(int x) {
if (x <= 2)
return 1;
return recursive(x - 1) + recursive(x - 2);
}

public int loop(int x) {
int f1 = 1;
int f2 = 1;

int[ i = 3; /* parse error: missing ']' */
while (i <= x) {
int temp f1; /* missing '=' */
f1 = f1 + f2;
f2 = temp;
i += 1;
}
return f1;
}
}; /* ';' not allowed */
50 changes: 50 additions & 0 deletions neg/negative3.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class BowlingGame {
public int[] rolls;/* = new int[21]; */
public int currentRoll; /* = 0 */

public void roll(int pins) { { /* not matching '}' */
currentRoll = currentRoll + 1;
rolls[currentRoll] = pins;
}

public int score() {
int score = 0;
int frameIndex = 0;
int frame = 0;
while(frame < 10)
{
if (isStrike(frameIndex)) {
score = score + 10 + strikeBonus(frameIndex);
frameIndex = frameIndex + 2;
} else if (isSpare(frameIndex)) {
score = score + 10 + spareBonus(frameIndex);
frameIndex = frameIndex + 2;
} else {
score = score + sumOfBallsInFrame(frameIndex);
frameIndex = frameIndex + 2;
}
frame++;
}
return score;
}

public boolean isStrike(int frameIndex) {
return rolls[frameIndex] == 10;
}

public int sumOfBallsInFrame(int frameIndex) {
return rolls[frameIndex] + rolls[frameIndex+1];
}

public int spareBonus(int frameIndex) {
return rolls[frameIndex+2];
}

public int strikeBonus(int frameIndex) {
return rolls[frameIndex+1] + rolls[frameIndex+2];
}

public boolean isSpare(int frameIndex) {
return rolls[frameIndex]+rolls[frameIndex+1] == 10;
}
}
15 changes: 15 additions & 0 deletions neg/negative4.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Dangler {

public int getValue() /* Missing '{' */
int a = 1;
int b = 0;

if (a == 1)
if (b == 1)
a = 42;
else /* Belongs to the last if!!!! Indentation is wrong on purpose. */
b = 42;

return b;
}
}
13 changes: 13 additions & 0 deletions neg/negative5.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Weird {
public int getValue() {
int a = 0;

if ((((a < 0)) && (a > 0) || !(a == 0)) { /* Missing ')' */
{ ;}
return -1;
} /* Missing '{' */
}

return a;
}
}
5 changes: 5 additions & 0 deletions pos-parser/positive1.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
public int getZero() {
return 0;
}
}
22 changes: 22 additions & 0 deletions pos-parser/positive2.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

class Fibonacci {
public int recursive(int x) {
if (x <= 2)
return 1;
return recursive(x - 1) + recursive(x - 2);
}

public int loop(int x) {
int f1 = 1;
int f2 = 1;

int i = 3;
while (i <= x) {
int temp = f1;
f1 = f1 + f2;
f2 = temp;
i =i+ 1;
}
return f1;
}
}
50 changes: 50 additions & 0 deletions pos-parser/positive3.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class BowlingGame {
public int[] rolls;/* = new int[21]; */
public int currentRoll; /* = 0 */

public void roll(int pins) {
currentRoll = currentRoll + 1;
rolls[currentRoll] = pins;
}

public int score() {
int score = 0;
int frameIndex = 0;
int frame = 0;
while(frame < 10)
{
if (isStrike(frameIndex)) {
score = score + 10 + strikeBonus(frameIndex);
frameIndex = frameIndex + 2;
} else if (isSpare(frameIndex)) {
score = score + 10 + spareBonus(frameIndex);
frameIndex = frameIndex + 2;
} else {
score = score + sumOfBallsInFrame(frameIndex);
frameIndex = frameIndex + 2;
}
frame = frame + 1;
}
return score;
}

public boolean isStrike(int frameIndex) {
return rolls[frameIndex] == 10;
}

public int sumOfBallsInFrame(int frameIndex) {
return rolls[frameIndex] + rolls[frameIndex+1];
}

public int spareBonus(int frameIndex) {
return rolls[frameIndex+2];
}

public int strikeBonus(int frameIndex) {
return rolls[frameIndex+1] + rolls[frameIndex+2];
}

public boolean isSpare(int frameIndex) {
return rolls[frameIndex]+rolls[frameIndex+1] == 10;
}
}
15 changes: 15 additions & 0 deletions pos-parser/positive4.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Dangler {

public int getValue() {
int a = 1;
int b = 0;

if (a == 1)
if (b == 1)
a = 42;
else /* Belongs to the last if!!!! Indentation is wrong on purpose. */
b = 42;

return b;
}
}
14 changes: 14 additions & 0 deletions pos-parser/positive5.mini.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Weird {
public int getValue() {
int a = 0;

if ((((a < 0)) && (a > 0) || !(a == 0))) {
{
{ ;}
return -1;
}
}

return a;
}
}

0 comments on commit 5376524

Please sign in to comment.