Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Grethe Sandstrak
SU1_Workshop_testing_2017
Commits
22b155ce
Commit
22b155ce
authored
Feb 07, 2018
by
Grethe Sandstrak
Browse files
Replace SpillTest.java
parent
35fbd6b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
testforst/alfabetspill_junit_tester/SpillTest.java
View file @
22b155ce
...
...
@@ -18,22 +18,22 @@ import static org.hamcrest.CoreMatchers.containsString;
* @author grethsan
*/
public
class
SpillTest
{
public
SpillTest
()
{
}
@BeforeClass
public
static
void
setUpClass
()
{
}
@AfterClass
public
static
void
tearDownClass
()
{
}
@Before
public
void
setUp
()
{
}
@After
public
void
tearDown
()
{
}
...
...
@@ -46,14 +46,14 @@ public class SpillTest {
System
.
out
.
println
(
"Spill: spillEnOmgang"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
String
result
=
instance
.
spillEnOmgang
();
String
expResult
=
""
;
boolean
spiller1VilBytte
=
spiller1
.
getBokstav
()
>
'M'
;
boolean
spiller2VilBytte
=
spiller2
.
getBokstav
()
>
'M'
;
boolean
byttet
=
spiller1VilBytte
&&
spiller2VilBytte
;
boolean
spiller2VilBytte
=
spiller2
.
getBokstav
()
>
'M'
;
boolean
byttet
=
spiller1VilBytte
&&
spiller2VilBytte
;
String
byttetLest
=
"De byttet ikke. "
;
if
(
byttet
){
byttetLest
=
"De byttet. "
;
...
...
@@ -62,11 +62,11 @@ public class SpillTest {
}
else
{
expResult
+=
spiller1
.
getNavn
()
+
" trakk "
+
spiller1
.
getBokstav
()
+
". "
;
expResult
+=
spiller2
.
getNavn
()
+
" trakk "
+
spiller2
.
getBokstav
()
+
". "
;
expResult
+=
spiller2
.
getNavn
()
+
" trakk "
+
spiller2
.
getBokstav
()
+
". "
;
}
expResult
+=
byttetLest
;
expResult
+=
spiller1
+
" og "
+
spiller2
;
assertEquals
(
expResult
,
result
);
}
...
...
@@ -78,9 +78,9 @@ public class SpillTest {
System
.
out
.
println
(
"Spill: bytteKort"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
instance
.
spillEnOmgang
();
char
spiller1Bokstav
=
spiller1
.
getBokstav
();
char
spiller2Bokstav
=
spiller2
.
getBokstav
();
instance
.
bytteKort
();
...
...
@@ -99,8 +99,8 @@ public class SpillTest {
System
.
out
.
println
(
"Spill: beregnPoengForEnOmgang"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
instance
.
spillEnOmgang
();
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
instance
.
spillEnOmgang
();
int
spiller1Poeng
=
0
;
int
spiller2Poeng
=
0
;
if
(
spiller1
.
getBokstav
()
<
spiller2
.
getBokstav
())
spiller1Poeng
++;
...
...
@@ -122,16 +122,16 @@ public class SpillTest {
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
String
expResult
=
"\n"
;
// mellom hver omgang skal det skrives et linjeskift..
String
result
=
instance
.
spillMangeOmganger
(
antallOmganger
);
Assert
.
assertThat
(
result
,
containsString
(
expResult
));
Assert
.
assertThat
(
result
,
containsString
(
expResult
));
}
@Test
(
expected
=
Exception
.
class
)
public
void
testSpillMangeOmganger_exeption
()
throws
Exception
{
System
.
out
.
println
(
"Spill: spillMangeOmganger"
);
System
.
out
.
println
(
"Spill: spillMangeOmganger"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
int
antallOmganger
=
14
;
// Blir en omgang for mye -
int
antallOmganger
=
14
;
// Blir en omgang for mye -
instance
.
spillMangeOmganger
(
antallOmganger
);
}
/**
...
...
@@ -142,13 +142,13 @@ public class SpillTest {
System
.
out
.
println
(
"Spill: avsluttSpill"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
instance
.
spillEnOmgang
();
String
expResult
=
"Det ble uavgjort"
;
if
(
spiller1
.
getAntallPoeng
()>
spiller2
.
getAntallPoeng
())
expResult
=
spiller1
.
getNavn
()
+
" vant:)"
;
else
if
(
spiller2
.
getAntallPoeng
()>
spiller1
.
getAntallPoeng
())
expResult
=
spiller2
.
getNavn
()
+
" vant:)"
;
String
result
=
instance
.
avsluttSpill
();
String
result
=
instance
.
avsluttSpill
();
assertEquals
(
expResult
,
result
);
}
...
...
@@ -160,7 +160,7 @@ public class SpillTest {
System
.
out
.
println
(
"Spill: toString"
);
Spiller
spiller1
=
new
Spiller
(
"Grethe"
);
Spiller
spiller2
=
new
Spiller
(
"Nils"
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
Spill
instance
=
new
Spill
(
spiller1
,
spiller2
);
instance
.
spillEnOmgang
();
String
expResult
=
spiller1
+
"\n"
+
spiller2
;
...
...
@@ -168,5 +168,8 @@ public class SpillTest {
assertEquals
(
expResult
,
result
);
}
public
static
void
main
(
String
args
[])
{
org
.
junit
.
runner
.
JUnitCore
.
main
(
SpillTest
.
class
.
getName
());
// tas med dersom textpad ikke er konfigurert
}
}
Write
Preview
Supports
Markdown
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