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
Haoyang Cui
SWEN90006-A1-2018
Commits
aeb53e1d
Commit
aeb53e1d
authored
6 years ago
by
Haoyang Cui
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
12597691
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
+1039
-0
1039 additions, 0 deletions
test/swen90006/machine/BoundaryTests.java
with
1039 additions
and
0 deletions
test/swen90006/machine/BoundaryTests.java
0 → 100644
+
1039
−
0
View file @
aeb53e1d
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
BoundaryTests
{
//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
()
{
}
// Test a valid input of add instruction.
// Test the boundary R0 of ret instruction
@Test
public
void
retInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of add instruction.
// Test the boundary R0 of ret instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
retInstructionInvalidRegisterTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"ret R-1;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary R31 of ret instruction
@Test
public
void
retInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of add instruction.
// Test the boundary R31 of ret instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
retInstructionInvalidRegisterTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"ret R32;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary R0 of mov instruction
@Test
public
void
movInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of add instruction.
// Test the boundary R0 of mov instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
movInstructionInvalidRegisterTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R-1 0;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary R31 of mov instruction
@Test
public
void
movInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of add instruction.
// Test the boundary R31 of mov instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
movInstructionInvalidRegisterTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R32 0;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary 65535 of mov instruction
@Test
public
void
movInstructionvValidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 65535;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
65535
);
}
// Test an invalid input of add instruction.
// Test the boundary 65535 of mov instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
movInstructionInvalidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 65536;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary -65535 of mov instruction
@Test
public
void
movInstructionvValidValueTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 -65535;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
-
65535
);
}
// Test an invalid input of add instruction.
// Test the boundary -65535 of mov instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
movInstructionInvalidValueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 -65536;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of add instruction.
// Test the boundary R0 of add instruction
@Test
public
void
addInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"add R0 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
3
);
}
// Test a invalid input of add instruction.
// Test the boundary R0 of add instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
addInstructionInValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"add R-1 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
3
);
}
// Test a valid input of add instruction.
// Test the boundary R31 of add instruction
@Test
public
void
addInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"add R31 R1 R2;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
3
);
}
// Test a invalid input of add instruction.
// Test the boundary R31 of add instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
addInstructionInValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"add R32 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of sub instruction.
// Test the boundary R0 of sub instruction
@Test
public
void
subInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"sub R0 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
-
1
);
}
// Test a invalid input of sub instruction.
// Test the boundary R0 of sub instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
subInstructionInValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"sub R-1 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of sub instruction.
// Test the boundary R31 of sub instruction
@Test
public
void
subInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"sub R31 R1 R2;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
-
1
);
}
// Test a invalid input of sub instruction.
// Test the boundary R31 of sub instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
subInstructionInValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"sub R32 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of mul instruction.
// Test the boundary R0 of mul instruction
@Test
public
void
mulInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mul R0 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a invalid input of mul instruction.
// Test the boundary R0 of mul instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
mulInstructionInValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"add R-1 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of mul instruction.
// Test the boundary R31 of mul instruction
@Test
public
void
mulInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mul R31 R1 R2;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a invalid input of mul instruction.
// Test the boundary R31 of mul instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
mulInstructionInValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mul R32 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of div instruction.
// Test the boundary R0 of div instruction
@Test
public
void
divInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"div R0 R2 R1;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a invalid input of div instruction.
// Test the boundary R0 of div instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
divInstructionInValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"div R-1 R2 R1;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of div instruction.
// Test the boundary R31 of div instruction
@Test
public
void
divInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"div R31 R2 R1;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a invalid input of div instruction.
// Test the boundary R31 of div instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
divInstructionInValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"div R32 R2 R1;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of div instruction.
// Test the boundary Rc not = 0 of div instruction has been covered before
// Test a valid input of div instruction.
// Test the boundary Rc = 0 of div instruction
@Test
public
void
divInstructionValidTest_div0
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 2;"
);
list
.
add
(
"mov R2 0;"
);
list
.
add
(
"div R0 R1 R2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test a valid input of ldr instruction.
// Test the boundary R0 of ldr instruction
@Test
public
void
ldrInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R1 R0 0;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of ldr instruction.
// Test the boundary R0 of ldr instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
ldrInstructionInvalidRegisterTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R-1 R0 0;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of ldr instruction.
// Test the boundary R31 of ldr instruction
@Test
public
void
ldrInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R31 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R31 R0 0;"
);
list
.
add
(
"ret R31;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of ldr instruction.
// Test the boundary R31 of ldr instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
ldrInstructionInvalidRegisterTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R32 R0 0;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of ldr instruction.
// Test the boundary 65535 of ldr instruction
@Test
public
void
ldrInstructionValidValueTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"str R0 65535 R2;"
);
list
.
add
(
"ldr R1 R0 65535;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of ldr instruction.
// Test the boundary 65535 of ldr instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
ldrInstructionInvalidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R1 R0 65536;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of ldr instruction.
// Test the boundary -65535 of ldr instruction
@Test
public
void
ldrInstructionValidValueTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"str R0 -65535 R2;"
);
list
.
add
(
"ldr R1 R0 -65535;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
1
);
}
// Test an invalid input of ldr instruction.
// Test the boundary -65535 of ldr instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
ldrInstructionInvalidValueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R1 R0 -65536;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of ldr instruction.
// Test the boundary R+v = 0 of ldr instruction
@Test
public
void
ldrInstructionValidAddressTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"ldr R1 R3 0;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test a valid input of ldr instruction.
// Test the boundary R+v >= 0 of ldr instruction
@Test
public
void
ldrInstructionInvalidAddressTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R4 -1;"
);
list
.
add
(
"ldr R1 R4 0;"
);
list
.
add
(
"ret R1;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
1
);
}
// Test a valid input of ldr instruction.
// Test the boundary R+v = 65535 of ldr instruction
@Test
public
void
ldrInstructionValidAddressTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R3 1;"
);
list
.
add
(
"mov R1 0;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R3 R1 65535;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test a valid input of ldr instruction.
// Test the boundary R+v = 65535 of ldr instruction
@Test
public
void
ldrInstructionInvalidAddressTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R3 1;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"ldr R3 R1 65535;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
1
);
}
// Test a valid input of str instruction.
// Test the boundary R0 of str instruction
@Test
public
void
strInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 0 R2;"
);
list
.
add
(
"ldr R3 R0 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of str instruction.
// Test the boundary R0 of str instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
strInstructionInvalidRegisterTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 0 R-1;"
);
list
.
add
(
"ldr R3 R0 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of str instruction.
// Test the boundary R31 of str instruction
@Test
public
void
strInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R31 0 R2;"
);
list
.
add
(
"ldr R3 R31 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of str instruction.
// Test the boundary R32 of str instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
strInstructionInvalidRegisterTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R32 0 R-1;"
);
list
.
add
(
"ldr R3 R31 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of str instruction.
// Test the boundary 65535 of str instruction
@Test
public
void
strInstructionValidValueTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 65535 R2;"
);
list
.
add
(
"ldr R3 R0 65535;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of str instruction.
// Test the boundary 65535 of str instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
strInstructionInvalidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 65536 R2;"
);
list
.
add
(
"ldr R3 R0 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of str instruction.
// Test the boundary -65535 of str instruction
@Test
public
void
strInstructionValidValueTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 -65535 R2;"
);
list
.
add
(
"ldr R3 R0 -65535;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an invalid input of str instruction.
// Test the boundary -65535 of str instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
strInstructionInvalidValueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 0;"
);
list
.
add
(
"str R0 -65536 R2;"
);
list
.
add
(
"ldr R3 R0 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of str instruction.
// Test the boundary R + v = 0 of str instruction
@Test
public
void
strInstructionValidAddress_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 3;"
);
list
.
add
(
"mov R4 0;"
);
list
.
add
(
"str R4 0 R2;"
);
list
.
add
(
"ldr R3 R4 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a valid input of str instruction.
// Test the boundary R + v = 0 of str instruction
@Test
public
void
strInstructionInvalidAddress_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 3;"
);
list
.
add
(
"mov R4 -1;"
);
list
.
add
(
"str R4 0 R2;"
);
list
.
add
(
"ldr R3 R4 0;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
3
);
}
// Test a valid input of str instruction.
// Test the boundary R + v = 0 of str instruction
@Test
public
void
strInstructionValidAddress_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 3;"
);
list
.
add
(
"str R1 65534 R2;"
);
list
.
add
(
"ldr R3 R1 65534;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test a valid input of str instruction.
// Test the boundary R + v = 65535 of str instruction
@Test
public
void
strInstructionInvalidAddress_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
"mov R1 1;"
);
list
.
add
(
"mov R2 2;"
);
list
.
add
(
"mov R3 3;"
);
list
.
add
(
"str R1 65535 R2;"
);
list
.
add
(
"ldr R3 R1 65535;"
);
list
.
add
(
"ret R3;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
3
);
}
// Test an invalid input of jmp instruction.
// Test the boundary v = 65535 of jmp instruction
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
jmpInstructionValidTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"jmp 65535;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test an invalid input of jmp instruction.
// Test the boundary v = 65535 of jmp instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jmpInstructionInvalidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"jmp 65536;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test an invalid input of jmp instruction.
// Test the boundary v = -65535 of jmp instruction
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
jmpInstructionValidTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"jmp -65535;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test an invalid input of jmp instruction.
// Test the boundary v = -65535 of jmp instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jmpInstructionInvalidValueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"jmp -65536;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of jz instruction.
// Test the boundary R31 of jz instruction
@Test
public
void
jzInstructionValidRegisterTest_high
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R31 0"
);
list
.
add
(
"jz R31 3;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"ret R0;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of jz instruction.
// Test the boundary R31 of jz instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jzInstructionInvalidRegisterTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R32 2;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"ret R0;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of jz instruction.
// Test the boundary R0 of jz instruction
@Test
public
void
jzInstructionValidRegisterTest_low
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R0 3;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"ret R0;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
2
);
}
// Test an invalid input of jz instruction.
// Test the boundary R0 of jz instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jzInstructionInvalidRegisterTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R32 2;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"ret R0;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of jz instruction.
// Test the boundary 65535 of jz instruction
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
jzInstructionInvalidValueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R0 65535;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test an invalid input of jz instruction.
// Test the boundary 65535 of jz instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jzInstructionInvalidInvalueTest_high
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R0 65536;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a valid input of jz instruction.
// Test the boundary -65535 of jz instruction
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
jzInstructionInvalidValueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R0 -65535;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test an invalid input of jz instruction.
// Test the boundary -65535 of jz instruction
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
jzInstructionInvalidInvalueTest_low
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0"
);
list
.
add
(
"jz R0 -65536;"
);
list
.
add
(
"mov R0 1;"
);
list
.
add
(
"mov R0 2;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
// Test a invalid input, valid covered above
@Test
(
expected
=
InvalidInstructionException
.
class
)
public
void
unrecognisedInstructionInvalidValueTest
()
throws
Throwable
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"move R0 0;"
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test an empty input, valid covered above
@Test
public
void
emptyInstructionInvalidValueTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
list
.
add
(
" "
);
list
.
add
(
"ret R0;"
);
Machine
m
=
new
Machine
();
assertEquals
(
m
.
execute
(
list
),
0
);
}
// Test a no return input, valid covered above
@Test
(
expected
=
NoReturnValueException
.
class
)
public
void
noReturnTest
()
{
List
<
String
>
list
=
new
ArrayList
<
String
>();
list
.
add
(
"mov R0 0;"
);
Machine
m
=
new
Machine
();
m
.
execute
(
list
);
}
}
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