Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SWEN90006-A1-2018
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hongyi Chen
SWEN90006-A1-2018
Commits
564dfcde
Commit
564dfcde
authored
Sep 3, 2018
by
Hongyi Chen
Browse files
Options
Downloads
Patches
Plain Diff
Replace BoundaryTests.java
parent
c9ea59b8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/swen90006/machine/BoundaryTests.java
+187
-28
187 additions, 28 deletions
test/swen90006/machine/BoundaryTests.java
with
187 additions
and
28 deletions
test/swen90006/machine/BoundaryTests.java
+
187
−
28
View file @
564dfcde
...
...
@@ -24,53 +24,212 @@ public class BoundaryTests
{
}
//Any method annotation with "@Test" is executed as a test.
@Test
public
void
aTest
()
@Test
public
void
B1TestCase
()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R0 0"
);
list
.
add
(
"RET R0"
);
Machine
machine
=
new
Machine
();
int
actual
=
0
;
// expected result
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B2TestCase
()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R31 31"
);
list
.
add
(
"RET R31"
);
Machine
machine
=
new
Machine
();
int
actual
=
31
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B5TestCase
()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 -65535"
);
list
.
add
(
"RET R1"
);
Machine
machine
=
new
Machine
();
int
actual
=
-
65535
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B6TestCase
()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 65535"
);
list
.
add
(
"RET R1"
);
Machine
machine
=
new
Machine
();
int
actual
=
65535
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B9TestCase
()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
final
int
expected
=
2
;
final
int
actual
=
1
+
1
;
assertEquals
(
expected
,
actual
);
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"JMP 0"
);
list
.
add
(
"MOV R1 0"
);
list
.
add
(
"RET R1"
);
Machine
machine
=
new
Machine
();
int
actual
=
0
;
// It should be a infinite loop.
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B10TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 10"
);
list
.
add
(
"MOV R2 12"
);
list
.
add
(
"JMP 2"
);
list
.
add
(
"RET R1"
);
list
.
add
(
"RET R2"
);
Machine
machine
=
new
Machine
();
int
actual
=
12
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
anotherTest
()
@Test
public
void
B13TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"a"
);
list
.
add
(
"b"
);
list
.
add
(
"MOV R1 0"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 0 R2"
);
list
.
add
(
"LDR R3 R1 0"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
100
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
//the assertTrue method is used to check whether something holds.
assertTrue
(
list
.
contains
(
"a"
));
@Test
public
void
B14TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 60000"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 5535 R2"
);
list
.
add
(
"LDR R3 R1 5535"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
100
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
//Test test opens a file and executes the machine
@Test
public
void
aFileOpenTest
()
@Test
public
void
B15TestCase
()
{
final
List
<
String
>
lines
=
readInstructions
(
"examples/array.s"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
lines
),
45
);
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R3 0"
);
list
.
add
(
"MOV R1 0"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 -1 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 -1"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
0
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B16TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R3 2"
);
list
.
add
(
"MOV R1 60000"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 5536 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 5536"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
2
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
//-------------------------------
//To test an exception, specify the expected exception after the @Test
@Test
(
expected
=
java
.
io
.
IOException
.
class
)
public
void
anExceptionTest
()
throws
Throwable
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
B3anInvalidInstructionExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R-1 -1"
);
list
.
add
(
"RET R-1"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
B4anInvalidInstructionExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R32 32"
);
list
.
add
(
"RET R32"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
B7anInvalidInstructionExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R2 -65536"
);
list
.
add
(
"RET R2"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
B8anInvalidInstructionExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R3 65536"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
B11anNoReturnValueExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 10"
);
list
.
add
(
"JMP -2"
);
list
.
add
(
"RET R1"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
B12anNoReturnValueExceptionTest
()
{
throw
new
java
.
io
.
IOException
();
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 10"
);
list
.
add
(
"JMP 2"
);
list
.
add
(
"RET R1"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
//This test should fail.
//To provide additional feedback when a test fails, an error message
//can be included
@Test
public
void
aFailedTest
()
//To test an exception, specify the expected exception after the @Test
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
EC3anInvalidInstructionException
()
{
//include a message for better feedback
final
int
expected
=
2
;
final
int
actual
=
1
+
2
;
assertEquals
(
"Some failure message"
,
ex
p
ecte
d
,
actual
);
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"CMP R1 R2"
)
;
Machine
machine
=
new
Machine
()
;
machine
.
exec
u
te
(
list
);
}
//Read in a file containing a program and convert into a list of
//string instructions
private
List
<
String
>
readInstructions
(
String
file
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment