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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hongyi Chen
SWEN90006-A1-2018
Commits
07d09e6a
Commit
07d09e6a
authored
6 years ago
by
Hongyi Chen
Browse files
Options
Downloads
Patches
Plain Diff
Replace BoundaryTests.java
parent
ff0c4fea
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
+90
-30
90 additions, 30 deletions
test/swen90006/machine/BoundaryTests.java
with
90 additions
and
30 deletions
test/swen90006/machine/BoundaryTests.java
+
90
−
30
View file @
07d09e6a
...
...
@@ -42,7 +42,9 @@ public class BoundaryTests
//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
(
"MOV R1 1"
);
list
.
add
(
"MOV R2 2"
);
list
.
add
(
"ADD R31 R1 R2"
);
list
.
add
(
"RET R31"
);
Machine
machine
=
new
Machine
();
int
actual
=
31
;
...
...
@@ -55,7 +57,9 @@ public class BoundaryTests
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 -65535"
);
list
.
add
(
"RET R1"
);
list
.
add
(
"MOV R2 1"
);
list
.
add
(
"DIV R3 R1 R2"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
-
65535
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
...
...
@@ -67,9 +71,11 @@ public class BoundaryTests
//equal, using the equals method
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 65535"
);
list
.
add
(
"RET R1"
);
list
.
add
(
"MOV R2 1"
);
list
.
add
(
"SUB R3 R1 R2"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
6553
5
;
int
actual
=
6553
4
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
...
...
@@ -102,10 +108,10 @@ public class BoundaryTests
@Test
public
void
B13TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1
0
"
);
list
.
add
(
"MOV R1
65535
"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1
0
R2"
);
list
.
add
(
"LDR R3 R1
0
"
);
list
.
add
(
"STR R1
-65535
R2"
);
list
.
add
(
"LDR R3 R1
-65535
"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
100
;
...
...
@@ -115,10 +121,10 @@ public class BoundaryTests
@Test
public
void
B14TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1
60000
"
);
list
.
add
(
"MOV R1
-65535
"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 5535 R2"
);
list
.
add
(
"LDR R3 R1 5535"
);
list
.
add
(
"STR R1
6
5535 R2"
);
list
.
add
(
"LDR R3 R1
6
5535"
);
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
100
;
...
...
@@ -128,32 +134,96 @@ public class BoundaryTests
@Test
public
void
B15TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R3 0"
);
list
.
add
(
"MOV R1 0"
);
list
.
add
(
"MOV R1 65535"
);
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
(
"STR R1
0
R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1
0
"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
0
;
int
actual
=
10
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 R1 0"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"STR R1 65535 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 65535"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
100
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B17TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 65534"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"MOV R3 333"
);
list
.
add
(
"STR R1 -65535 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 -65535"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
333
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B18TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 -65535"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"MOV R3 333"
);
list
.
add
(
"STR R1 65534 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 65534"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
333
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B19TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 65535"
);
list
.
add
(
"MOV R2 100"
);
list
.
add
(
"MOV R3 333"
);
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
=
333
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
@Test
public
void
B20TestCase
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"MOV R1 1"
);
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
(
"MOV R3 333"
);
list
.
add
(
"STR R1 65535 R2"
);
// instruction does nothing
list
.
add
(
"LDR R3 R1 65535"
);
// instruction does nothing
list
.
add
(
"RET R3"
);
Machine
machine
=
new
Machine
();
int
actual
=
2
;
int
actual
=
333
;
assertEquals
(
machine
.
execute
(
list
),
actual
);
}
//-------------------------------
//To test an exception, specify the expected exception after the @Test
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
B0anNoReturnValueExceptionTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
""
);
//EMPTY LIST
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
B3anInvalidInstructionExceptionTest
()
{
...
...
@@ -218,16 +288,6 @@ public class BoundaryTests
}
//To test an exception, specify the expected exception after the @Test
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
EC3anInvalidInstructionException
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"CMP R1 R2"
);
Machine
machine
=
new
Machine
();
machine
.
execute
(
list
);
}
//Read in a file containing a program and convert into a list of
...
...
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