Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fault Tree Project
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
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
STAR 2021 Group 6
Fault Tree Project
Commits
6488dc7b
Commit
6488dc7b
authored
4 years ago
by
IrinaShcherbakova
Browse files
Options
Downloads
Patches
Plain Diff
tests for H1, H2, H3 and new test tree4
parent
9b57464c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
analysis/Main/Test.java
+142
-2
142 additions, 2 deletions
analysis/Main/Test.java
with
142 additions
and
2 deletions
analysis/Main/Test.java
+
142
−
2
View file @
6488dc7b
...
...
@@ -3,8 +3,7 @@ package Main;
import
java.util.HashMap
;
import
FaultTree.*
;
import
Heuristics.ByWeightHeuristic
;
import
Heuristics.FaninHeuristic
;
import
Heuristics.*
;
public
class
Test
{
// Test tree definitions
...
...
@@ -70,6 +69,18 @@ public class Test {
t3_b9
),
t3_b1
)));
static
BasicEvent
t4_b1
=
new
BasicEvent
(
2
,
"B1"
);
static
BasicEvent
t4_b2
=
new
BasicEvent
(
4
,
"B2"
);
static
BasicEvent
t4_b3
=
new
BasicEvent
(
5
,
"B3"
);
static
BasicEvent
t4_b4
=
new
BasicEvent
(
8
,
"B4"
);
static
BasicEvent
t4_b5
=
new
BasicEvent
(
9
,
"B5"
);
static
IntermediateEvent
t4_e2
=
new
IntermediateEvent
(
3
,
"E2"
,
Type
.
And
,
t4_b2
,
t4_b3
);
static
IntermediateEvent
t4_e5
=
new
IntermediateEvent
(
5
,
"E5"
,
Type
.
And
,
t4_b3
,
t4_b4
);
static
IntermediateEvent
t4_e1
=
new
IntermediateEvent
(
1
,
"E1"
,
Type
.
And
,
t4_b1
,
t4_e2
);
static
IntermediateEvent
t4_e4
=
new
IntermediateEvent
(
2
,
"E4"
,
Type
.
And
,
t4_e2
,
t4_b5
);
static
IntermediateEvent
t4_e3
=
new
IntermediateEvent
(
4
,
"E3"
,
Type
.
And
,
t4_e4
,
t4_e5
);
static
FaultTree
testTree4
=
new
IntermediateEvent
(
0
,
"Top"
,
Type
.
And
,
t4_e1
,
t4_e3
);
// Test helper
private
static
<
T
>
void
expectEquals
(
T
actual
,
T
expected
,
String
title
)
{
if
(
actual
.
equals
(
expected
))
{
...
...
@@ -148,8 +159,137 @@ public class Test {
expectEquals
(
heuristic
.
getOrder
(
testTree3
),
expectedOrder3
,
"Fanin Heuristic on tree 3"
);
}
private
static
void
testDFSHeuristic
()
{
var
expectedOrder1
=
new
HashMap
<>()
{{
put
(
t1_b1
,
0
);
put
(
t1_b4
,
1
);
put
(
t1_b5
,
2
);
put
(
t1_b6
,
3
);
}};
var
expectedOrder2
=
new
HashMap
<>()
{{
put
(
t2_b1
,
0
);
put
(
t2_b2
,
1
);
put
(
t2_b3
,
2
);
put
(
t2_b4
,
3
);
}};
var
expectedOrder3
=
new
HashMap
<>()
{{
put
(
t3_b1
,
0
);
put
(
t3_b2
,
1
);
put
(
t3_b3
,
2
);
put
(
t3_b4
,
3
);
put
(
t3_b5
,
4
);
put
(
t3_b6
,
5
);
put
(
t3_b7
,
6
);
put
(
t3_b8
,
7
);
put
(
t3_b9
,
8
);
}};
var
expectedOrder4
=
new
HashMap
<>()
{{
put
(
t4_b1
,
0
);
put
(
t4_b2
,
1
);
put
(
t4_b3
,
2
);
put
(
t4_b4
,
4
);
put
(
t4_b5
,
3
);
}};
var
heuristic
=
new
DepthFirstHeuristic
();
expectEquals
(
heuristic
.
getOrder
(
testTree1
),
expectedOrder1
,
"DFS Heuristic on tree 1"
);
expectEquals
(
heuristic
.
getOrder
(
testTree2
),
expectedOrder2
,
"DFS Heuristic on tree 2"
);
expectEquals
(
heuristic
.
getOrder
(
testTree3
),
expectedOrder3
,
"DFS Heuristic on tree 3"
);
expectEquals
(
heuristic
.
getOrder
(
testTree4
),
expectedOrder4
,
"DFS Heuristic on tree 4"
);
}
private
static
void
testBFSHeuristic
()
{
var
expectedOrder1
=
new
HashMap
<>()
{{
put
(
t1_b1
,
0
);
put
(
t1_b4
,
2
);
put
(
t1_b5
,
3
);
put
(
t1_b6
,
1
);
}};
var
expectedOrder2
=
new
HashMap
<>()
{{
put
(
t2_b1
,
0
);
put
(
t2_b2
,
2
);
put
(
t2_b3
,
1
);
put
(
t2_b4
,
3
);
}};
var
expectedOrder3
=
new
HashMap
<>()
{{
put
(
t3_b1
,
0
);
put
(
t3_b2
,
1
);
put
(
t3_b3
,
3
);
put
(
t3_b4
,
8
);
put
(
t3_b5
,
4
);
put
(
t3_b6
,
5
);
put
(
t3_b7
,
2
);
put
(
t3_b8
,
6
);
put
(
t3_b9
,
7
);
}};
var
expectedOrder4
=
new
HashMap
<>()
{{
put
(
t4_b1
,
0
);
put
(
t4_b2
,
1
);
put
(
t4_b3
,
2
);
put
(
t4_b4
,
4
);
put
(
t4_b5
,
3
);
}};
var
heuristic
=
new
BreadthFirstHeuristic
();
expectEquals
(
heuristic
.
getOrder
(
testTree1
),
expectedOrder1
,
"BFS Heuristic on tree 1"
);
expectEquals
(
heuristic
.
getOrder
(
testTree2
),
expectedOrder2
,
"BFS Heuristic on tree 2"
);
expectEquals
(
heuristic
.
getOrder
(
testTree3
),
expectedOrder3
,
"BFS Heuristic on tree 3"
);
expectEquals
(
heuristic
.
getOrder
(
testTree4
),
expectedOrder4
,
"BFS Heuristic on tree 4"
);
}
private
static
void
testByLevelHeuristic
()
{
var
expectedOrder1
=
new
HashMap
<>()
{{
put
(
t1_b1
,
0
);
put
(
t1_b4
,
2
);
put
(
t1_b5
,
3
);
put
(
t1_b6
,
1
);
}};
var
expectedOrder2
=
new
HashMap
<>()
{{
put
(
t2_b1
,
0
);
put
(
t2_b2
,
1
);
put
(
t2_b3
,
2
);
put
(
t2_b4
,
3
);
}};
var
expectedOrder3
=
new
HashMap
<>()
{{
put
(
t3_b1
,
2
);
put
(
t3_b2
,
0
);
put
(
t3_b3
,
3
);
put
(
t3_b4
,
7
);
put
(
t3_b5
,
8
);
put
(
t3_b6
,
4
);
put
(
t3_b7
,
1
);
put
(
t3_b8
,
5
);
put
(
t3_b9
,
6
);
}};
var
expectedOrder4
=
new
HashMap
<>()
{{
put
(
t4_b1
,
0
);
put
(
t4_b2
,
3
);
put
(
t4_b3
,
4
);
put
(
t4_b4
,
2
);
put
(
t4_b5
,
1
);
}};
var
heuristic
=
new
ByLevelHeuristic
();
expectEquals
(
heuristic
.
getOrder
(
testTree1
),
expectedOrder1
,
"By level Heuristic on tree 1"
);
expectEquals
(
heuristic
.
getOrder
(
testTree2
),
expectedOrder2
,
"By level Heuristic on tree 2"
);
expectEquals
(
heuristic
.
getOrder
(
testTree3
),
expectedOrder3
,
"By level Heuristic on tree 3"
);
expectEquals
(
heuristic
.
getOrder
(
testTree4
),
expectedOrder4
,
"By level Heuristic on tree 4"
);
}
public
static
void
main
(
String
[]
args
)
{
testByWeightHeuristic
();
testFaninHeuristic
();
testDFSHeuristic
();
testBFSHeuristic
();
testByLevelHeuristic
();
}
}
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