-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from jspam/005-42
Add tests by group FortyTwo
- Loading branch information
Showing
10 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
public int getZero(int) { | ||
return = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
public int getZero() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |