Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LI Qi
Bowling
Commits
40052ea2
Commit
40052ea2
authored
Feb 24, 2016
by
Qi LI
Browse files
add/modify test cases to optimize code coverage
parent
11838425
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/test/TestFrame.java
View file @
40052ea2
...
...
@@ -12,7 +12,7 @@ public class TestFrame {
public
void
testCase0
()
throws
Exception
{
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
7
);
Assert
.
assertEquals
(
Assert
.
assert
Array
Equals
(
new
boolean
[]
{
false
,
false
,
false
},
new
boolean
[]
{
frame
.
isFinished
(),
frame
.
isSpare
(),
frame
.
isStrike
()});
}
...
...
@@ -21,7 +21,7 @@ public class TestFrame {
public
void
testCase1
()
throws
Exception
{
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
10
);
Assert
.
assertEquals
(
Assert
.
assert
Array
Equals
(
new
boolean
[]
{
true
,
false
,
true
},
new
boolean
[]
{
frame
.
isFinished
(),
frame
.
isSpare
(),
frame
.
isStrike
()});
}
...
...
@@ -31,7 +31,7 @@ public class TestFrame {
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
7
);
frame
.
enterPoint
(
3
);
Assert
.
assertEquals
(
Assert
.
assert
Array
Equals
(
new
boolean
[]
{
true
,
true
,
false
},
new
boolean
[]
{
frame
.
isFinished
(),
frame
.
isSpare
(),
frame
.
isStrike
()});
}
...
...
@@ -41,8 +41,23 @@ public class TestFrame {
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
7
);
frame
.
enterPoint
(
0
);
Assert
.
assertEquals
(
Assert
.
assert
Array
Equals
(
new
boolean
[]
{
true
,
false
,
false
},
new
boolean
[]
{
frame
.
isFinished
(),
frame
.
isSpare
(),
frame
.
isStrike
()});
}
@Test
(
expected
=
Exception
.
class
)
public
void
testCase4
()
throws
Exception
{
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
11
);
Assert
.
assertNotNull
(
frame
);
}
@Test
(
expected
=
Exception
.
class
)
public
void
testCase5
()
throws
Exception
{
Frame
frame
=
new
Frame
(
0
);
frame
.
enterPoint
(
4
);
frame
.
enterPoint
(
7
);
Assert
.
assertNotNull
(
frame
);
}
}
src/test/TestPlayer.java
View file @
40052ea2
...
...
@@ -16,8 +16,17 @@ public class TestPlayer {
}
@Test
public
void
test
Joueu
rConstructor
()
{
public
void
test
Playe
rConstructor
()
{
Assert
.
assertNotNull
(
player
);
Assert
.
assertEquals
(
name
,
player
.
getName
());
Assert
.
assertEquals
(
name
,
player
.
toString
());
}
@Test
public
void
testQuitGame
()
{
player
.
quitNow
();
Assert
.
assertTrue
(
player
.
isOff
());
player
.
onGame
();
Assert
.
assertFalse
(
player
.
isOff
());
}
}
src/test/TestScoreTable.java
View file @
40052ea2
...
...
@@ -96,7 +96,7 @@ public class TestScoreTable {
}
expected
[
expected
.
length
-
1
]
=
true
;
Assert
.
assertEquals
(
expected
,
actual
);
Assert
.
assert
Array
Equals
(
expected
,
actual
);
}
@Test
...
...
@@ -113,7 +113,7 @@ public class TestScoreTable {
}
expected
[
expected
.
length
-
1
]
=
true
;
Assert
.
assertEquals
(
expected
,
actual
);
Assert
.
assert
Array
Equals
(
expected
,
actual
);
}
@Test
...
...
@@ -130,7 +130,7 @@ public class TestScoreTable {
}
expected
[
expected
.
length
-
1
]
=
true
;
Assert
.
assertEquals
(
expected
,
actual
);
Assert
.
assert
Array
Equals
(
expected
,
actual
);
}
@Test
...
...
@@ -147,6 +147,22 @@ public class TestScoreTable {
}
expected
[
expected
.
length
-
1
]
=
true
;
Assert
.
assertEquals
(
expected
,
actual
);
Assert
.
assertArrayEquals
(
expected
,
actual
);
}
@Test
public
void
testCase10
()
throws
Exception
{
ScoreTable
table
=
new
ScoreTable
();
int
[]
points
=
{
7
,
3
,
2
,
6
,
1
,
9
,
10
};
for
(
int
p
:
points
)
table
.
enterPoint
(
p
);
String
tableString
=
""
;
tableString
+=
"| 7 3| 2 6| 1 9| 10 0"
;
tableString
+=
"\n"
;
tableString
+=
"| 12 | 20 | 40 | 50 "
;
//System.out.println(tableString);
Assert
.
assertEquals
(
tableString
,
table
.
readTable
());
}
}
src/test/TestSet.java
View file @
40052ea2
...
...
@@ -4,6 +4,7 @@ import java.util.Arrays;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.internal.Throwables
;
import
game.Player
;
import
game.Set
;
...
...
@@ -12,7 +13,7 @@ public class TestSet {
public
TestSet
()
{}
@Test
public
void
testCase0
()
{
public
void
testCase0
()
throws
Exception
{
Player
alice
=
new
Player
(
"Alice"
);
Player
bob
=
new
Player
(
"Bob"
);
Set
set
=
new
Set
(
Arrays
.
asList
(
new
Player
[]
{
alice
,
bob
}));
...
...
@@ -30,7 +31,7 @@ public class TestSet {
}
@Test
public
void
testCase1
()
{
public
void
testCase1
()
throws
Exception
{
Player
alice
=
new
Player
(
"Alice"
);
Player
bob
=
new
Player
(
"Bob"
);
Player
charlie
=
new
Player
(
"Charlie"
);
...
...
@@ -50,12 +51,49 @@ public class TestSet {
for
(
int
i
=
0
;
i
<
points
.
length
;
++
i
)
{
actualPlayer
[
i
]
=
set
.
getNextPlayer
();
set
.
enterPoint
(
points
[
i
]);
expectedOver
[
i
]
=
false
;
actualOver
[
i
]
=
set
.
isOver
();
}
expectedOver
[
points
.
length
-
1
]
=
true
;
Assert
.
assertArrayEquals
(
expectedPlayer
,
actualPlayer
);
Assert
.
assertEquals
(
expectedOver
,
actualOver
);
Assert
.
assertArrayEquals
(
expectedOver
,
actualOver
);
}
@Test
public
void
testCase2
()
throws
Exception
{
Player
alice
=
new
Player
(
"Alice"
);
Player
bob
=
new
Player
(
"Bob"
);
Set
set
=
new
Set
(
Arrays
.
asList
(
new
Player
[]{
alice
,
bob
}));
set
.
enterPoint
(
7
);
set
.
enterPoint
(
3
);
Assert
.
assertTrue
(
set
.
getWinner
()
==
alice
);
}
@Test
public
void
testCase3
()
throws
Exception
{
Player
alice
=
new
Player
(
"Alice"
);
Player
bob
=
new
Player
(
"Bob"
);
Set
set
=
new
Set
(
Arrays
.
asList
(
new
Player
[]{
alice
,
bob
}));
set
.
enterPoint
(
10
);
set
.
enterPoint
(
7
);
set
.
enterPoint
(
2
);
set
.
enterPoint
(
3
);
String
scoreTable
=
""
;
scoreTable
+=
"| 10 0| 3 0"
;
scoreTable
+=
"\n"
;
scoreTable
+=
"| 13 | 16 "
;
Assert
.
assertEquals
(
scoreTable
,
set
.
getScoreTable
(
alice
));
scoreTable
=
""
;
scoreTable
+=
"| 7 2"
;
scoreTable
+=
"\n"
;
scoreTable
+=
"| 9 "
;
Assert
.
assertEquals
(
scoreTable
,
set
.
getScoreTable
(
bob
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment