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
He Zhu
SWEN90006-A1-2018
Commits
3dc596b9
Commit
3dc596b9
authored
Sep 2, 2018
by
He Zhu
Browse files
Options
Downloads
Patches
Plain Diff
Delete PartitioningTests.java
parent
c747920c
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
+0
-160
0 additions, 160 deletions
test/swen90006/machine/PartitioningTests.java
with
0 additions
and
160 deletions
test/swen90006/machine/PartitioningTests.java
deleted
100644 → 0
+
0
−
160
View file @
c747920c
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
{
Machine
m
=
new
Machine
();
//Test when the Ra in RET does not hold any value
@Test
public
void
TestEC1
()
{
final
List
<
String
>
lines
=
readInstructions
(
"ec1.s"
);
m
.
execute
(
lines
);
//if the first line is RET, the Ra is not assigned
assertTrue
(
lines
.
get
(
0
).
substring
(
0
,
3
).
equals
(
"RET"
));
}
//Test when the register name is out of range
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
TestEC2
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec2.s"
);
m
.
execute
(
lines
);
throw
new
InvalidInstructionException
();
}
//Test when dividend is 0
@Test
public
void
TestEC3
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec3.s"
);
m
.
execute
(
lines
);
//"no op" for dividend is 0, so there should throw no exception
}
//Test valid input JMP with value is 1
@Test
public
void
TestEC5
()
{
final
List
<
String
>
lines
=
readInstructions
(
"ec5.s"
);
m
.
execute
(
lines
);
}
//Test valid input JMP with value is greater than 1
@Test
public
void
TestEC6
()
{
final
List
<
String
>
lines
=
readInstructions
(
"ec6.s"
);
m
.
execute
(
lines
);
}
//Test invalid input JMP with value is greater than the list length
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
TestEC7
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec7.s"
);
m
.
execute
(
lines
);
throw
new
NoReturnValueException
();
}
//Test invalid input with no RET instruction included
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
TestEC8
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec8.s"
);
m
.
execute
(
lines
);
throw
new
NoReturnValueException
();
}
//Test invalid MOV instruction with assign double number to register
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
TestEC10
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec10.s"
);
m
.
execute
(
lines
);
throw
new
InvalidInstructionException
();
}
//Test invalid LDR instruction with assign pc with negative number
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
TestEC11
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec11.s"
);
m
.
execute
(
lines
);
throw
new
InvalidInstructionException
();
}
//Test valid input without a JZ instruction
@Test
public
void
TestEC12
()
{
final
List
<
String
>
lines
=
readInstructions
(
"ec12.s"
);
m
.
execute
(
lines
);
}
//Test valid input with Ra holds value 0
@Test
public
void
TestEC13
()
{
final
List
<
String
>
lines
=
readInstructions
(
"ec13.s"
);
m
.
execute
(
lines
);
}
//Test invalid JZ input with pc over the length of the list
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
TestEC14
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec14.s"
);
m
.
execute
(
lines
);
throw
new
NoReturnValueException
();
}
//Test valid JZ input with Ra is not 0
@Test
public
void
TestEC15
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec15.s"
);
m
.
execute
(
lines
);
}
//Test invalid LDR input with Rb doesn't hold any value
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
TestEC16
()
throws
Throwable
{
final
List
<
String
>
lines
=
readInstructions
(
"ec16.s"
);
m
.
execute
(
lines
);
throw
new
NoReturnValueException
();
}
//This test should fail.
//To provide additional feedback when a test fails, an error message
//can be included
@Test
public
void
aFailedTest
()
{
//include a message for better feedback
final
int
expected
=
2
;
final
int
actual
=
1
+
2
;
assertEquals
(
"Some failure message"
,
expected
,
actual
);
}
//Read in a file containing a program and convert into a list of
//string instructions
private
List
<
String
>
readInstructions
(
String
file
)
{
Charset
charset
=
Charset
.
forName
(
"UTF-8"
);
List
<
String
>
lines
=
null
;
try
{
lines
=
Files
.
readAllLines
(
FileSystems
.
getDefault
().
getPath
(
file
),
charset
);
}
catch
(
Exception
e
){
System
.
err
.
println
(
"Invalid input file! (stacktrace follows)"
);
e
.
printStackTrace
(
System
.
err
);
System
.
exit
(
1
);
}
return
lines
;
}
}
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