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
Jiaming Zhang
SWEN90006-A1-2018
Commits
65abe9f0
Commit
65abe9f0
authored
6 years ago
by
Jiaming Zhang
Browse files
Options
Downloads
Patches
Plain Diff
partitioning test
parent
7500d0b1
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/PartitioningTests.java
+229
-0
229 additions, 0 deletions
test/swen90006/machine/PartitioningTests.java
with
229 additions
and
0 deletions
test/swen90006/machine/PartitioningTests.java
0 → 100644
+
229
−
0
View file @
65abe9f0
package
swen90006.machine
;
import
java.util.List
;
import
java.util.ArrayList
;
import
java.nio.charset.Charset
;
import
java.nio.file.Path
;
import
java.nio.file.Files
;
import
java.nio.file.FileSystems
;
import
org.junit.*
;
import
static
org
.
junit
.
Assert
.*;
public
class
PartitioningTests
{
//Any method annotated with "@Before" will be executed before each test,
//allowing the tester to set up some shared resources.
@Before
public
void
setUp
()
{
}
//Any method annotated with "@After" will be executed after each test,
//allowing the tester to release any shared resources used in the setup.
@After
public
void
tearDown
()
{
}
//To test EC5 in Machine.
@Test
public
void
ec5Test
()
{
final
int
expected
=
0
;
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"RET R0 R1"
);
Machine
m
=
new
Machine
();
assertEquals
(
expected
,
m
.
execute
(
instructions
));
}
//To test EC6 in Machine.
@Test
public
void
ec6Test
()
{
final
NoReturnValueException
expected
=
new
NoReturnValueException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"MOV R0 1"
);
instructions
.
add
(
"MOV R1 1"
);
instructions
.
add
(
"ADD R2 R0 R1"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
NoReturnValueException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC7 in Machine.
@Test
public
void
ec7Test
()
{
final
int
expected
=
0
;
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"ADD R2 R0 R1"
);
instructions
.
add
(
"RET R2"
);
Machine
m
=
new
Machine
();
assertEquals
(
expected
,
m
.
execute
(
instructions
));
}
//To test EC8 in Machine.
@Test
public
void
ec8Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"ADD R2 R0 R32"
);
instructions
.
add
(
"RET R2"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC9 in Machine.
@Test
public
void
ec9Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"ADD R2 R0"
);
instructions
.
add
(
"RET R2"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC11 in Machine.
@Test
public
void
ec11Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"LDR R2 R0 -1"
);
instructions
.
add
(
"RET R2"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC13 in Machine.
@Test
public
void
ec13Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"LDR R2 R0 65536"
);
instructions
.
add
(
"RET R2"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC18 in Machine.
@Test
public
void
ec18Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"JMP -65536"
);
instructions
.
add
(
"RET R0"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC20 in Machine.
@Test
public
void
ec20Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"JMP 65536"
);
instructions
.
add
(
"RET R0"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC21 in Machine.
@Test
public
void
ec21Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"JMP abc"
);
instructions
.
add
(
"RET R0"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC22 in Machine.
@Test
public
void
ec22Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"RET R0"
);
instructions
.
add
(
"RET R1"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
//To test EC23 in Machine.
@Test
public
void
ec23Test
()
{
final
InvalidInstructionException
expected
=
new
InvalidInstructionException
();
final
List
<
String
>
instructions
=
new
ArrayList
<>();
instructions
.
add
(
"R0"
);
Machine
m
=
new
Machine
();
try
{
m
.
execute
(
instructions
);
}
catch
(
InvalidInstructionException
e
){
assertSame
(
expected
.
toString
(),
e
.
toString
());
return
;
}
assertEquals
(
expected
.
toString
(),
m
.
execute
(
instructions
));
}
}
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