Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
bf25dcf1
Commit
bf25dcf1
authored
Sep 15, 2016
by
Jakob Schöttl
Browse files
Add tests for train model and fix bug
parent
5456f584
Changes
3
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/models/seating/trainmodel/Compartment.java
View file @
bf25dcf1
...
...
@@ -9,20 +9,47 @@ public class Compartment {
private
TrainModel
trainModel
;
private
int
index
;
private
List
<
SeatGroup
>
seatGroups
;
public
Compartment
(
TrainModel
trainModel
,
int
index
)
{
this
.
trainModel
=
trainModel
;
this
.
index
=
index
;
seatGroups
=
new
ArrayList
<>(
4
);
if
(
index
==
0
)
{
addFirstHalfCompartment
();
}
else
if
(
index
==
trainModel
.
getNumberOfEntranceAreas
())
{
addLastHalfCompartment
();
}
else
{
addNormalCompartment
();
}
}
private
void
addNormalCompartment
()
{
final
int
startSeatGroupIndex
=
index
*
4
-
2
;
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
startSeatGroupIndex
));
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
startSeatGroupIndex
+
1
));
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
startSeatGroupIndex
+
2
));
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
startSeatGroupIndex
+
3
));
}
private
void
addFirstHalfCompartment
()
{
seatGroups
.
add
(
null
);
seatGroups
.
add
(
null
);
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
0
));
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
1
));
}
private
void
addLastHalfCompartment
()
{
final
int
n
=
trainModel
.
getSeatGroups
().
size
();
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
n
-
2
));
seatGroups
.
add
(
trainModel
.
getSeatGroup
(
n
-
1
));
seatGroups
.
add
(
null
);
seatGroups
.
add
(
null
);
}
public
List
<
SeatGroup
>
getSeatGroups
()
{
List
<
SeatGroup
>
result
=
new
ArrayList
<>(
4
);
final
int
startSeatGroupIndex
=
index
*
4
;
result
.
add
(
trainModel
.
getSeatGroups
().
get
(
startSeatGroupIndex
));
result
.
add
(
trainModel
.
getSeatGroups
().
get
(
startSeatGroupIndex
+
1
));
result
.
add
(
trainModel
.
getSeatGroups
().
get
(
startSeatGroupIndex
+
2
));
result
.
add
(
trainModel
.
getSeatGroups
().
get
(
startSeatGroupIndex
+
3
));
return
result
;
return
seatGroups
;
}
public
Target
getInterimTargetCloserTo
(
int
entranceAreaIndex
)
{
...
...
VadereSimulator/testResources/data/test-train-topography.json
0 → 100644
View file @
bf25dcf1
This source diff could not be displayed because it is too large. You can
view the blob
instead.
VadereSimulator/tests/org/vadere/simulator/models/seating/trainmodel/TestTrainModel.java
0 → 100644
View file @
bf25dcf1
package
org.vadere.simulator.models.seating.trainmodel
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Scanner
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.vadere.simulator.projects.io.JsonConverter
;
import
org.vadere.simulator.projects.io.TextOutOfNodeException
;
import
org.vadere.state.scenario.Et423Geometry
;
import
org.vadere.state.scenario.Topography
;
public
class
TestTrainModel
{
private
static
final
int
nEntranceAreas
=
12
;
private
static
final
int
nCompartments
=
nEntranceAreas
+
1
;
// includes 2 half-compartments
private
static
final
int
nInterimDestinations
=
nCompartments
*
3
-
4
;
// includes 2 targets from half-compartments
private
static
final
int
nSeatGroups
=
nCompartments
*
4
-
4
;
private
static
final
int
nSeats
=
nSeatGroups
*
4
;
private
TrainModel
trainModel
;
@Before
public
void
setUp
()
{
try
{
@SuppressWarnings
(
"resource"
)
final
String
json
=
new
Scanner
(
TestTrainModel
.
class
.
getResourceAsStream
(
"/data/test-train-topography.json"
),
"UTF-8"
).
useDelimiter
(
"\\A"
).
next
();
final
Topography
topography
=
JsonConverter
.
deserializeTopography
(
json
);
trainModel
=
new
TrainModel
(
topography
,
new
Et423Geometry
());
}
catch
(
IOException
|
TextOutOfNodeException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
e
);
}
}
@Test
public
void
testBasicModelProperties
()
{
assertEquals
(
nEntranceAreas
,
trainModel
.
getNumberOfEntranceAreas
());
checkSize
(
nInterimDestinations
,
trainModel
.
getInterimDestinations
());
checkSize
(
nSeatGroups
,
trainModel
.
getSeatGroups
());
checkSize
(
nSeats
,
trainModel
.
getSeats
());
// assertEquals(10, trainModel.getPedestrians().size());
}
@Test
public
void
testGetSeatGroupLimits
()
{
assertTrue
(
trainModel
.
getSeatGroup
(
0
)
!=
null
);
try
{
trainModel
.
getSeatGroup
(-
1
);
fail
(
"exception expected"
);
}
catch
(
IndexOutOfBoundsException
e
)
{
}
assertTrue
(
trainModel
.
getSeatGroup
(
nSeatGroups
-
1
)
!=
null
);
try
{
trainModel
.
getSeatGroup
(
nSeatGroups
);
fail
(
"exception expected"
);
}
catch
(
IndexOutOfBoundsException
e
)
{
}
}
@Test
public
void
testGetCompartmentLimits
()
{
assertTrue
(
trainModel
.
getCompartment
(
0
)
!=
null
);
// first half-compartment
assertTrue
(
trainModel
.
getCompartment
(
1
)
!=
null
);
// first normal compartment
try
{
trainModel
.
getCompartment
(-
1
);
fail
(
"exception expected"
);
}
catch
(
IndexOutOfBoundsException
e
)
{
}
assertTrue
(
trainModel
.
getCompartment
(
nCompartments
-
2
)
!=
null
);
// last normal compartment
assertTrue
(
trainModel
.
getCompartment
(
nCompartments
-
1
)
!=
null
);
// last half-compartment
try
{
trainModel
.
getCompartment
(
nCompartments
);
fail
(
"exception expected"
);
}
catch
(
IndexOutOfBoundsException
e
)
{
}
}
@Test
public
void
testFirstHalfCompartment
()
{
final
Compartment
c
=
trainModel
.
getCompartment
(
0
);
assertTrue
(
c
.
getSeatGroups
().
get
(
0
)
==
null
);
assertTrue
(
c
.
getSeatGroups
().
get
(
1
)
==
null
);
assertTrue
(
c
.
getSeatGroups
().
get
(
2
)
==
trainModel
.
getSeatGroup
(
0
));
assertTrue
(
c
.
getSeatGroups
().
get
(
3
)
==
trainModel
.
getSeatGroup
(
1
));
assertTrue
(
c
.
getSeatGroups
().
get
(
2
).
getSeat
(
0
)
==
trainModel
.
getSeats
().
get
(
0
));
}
@Test
public
void
testLastHalfCompartment
()
{
final
Compartment
c
=
trainModel
.
getCompartment
(
nCompartments
-
1
);
assertTrue
(
c
.
getSeatGroups
().
get
(
0
)
==
trainModel
.
getSeatGroup
(
nSeatGroups
-
2
));
assertTrue
(
c
.
getSeatGroups
().
get
(
1
)
==
trainModel
.
getSeatGroup
(
nSeatGroups
-
1
));
assertTrue
(
c
.
getSeatGroups
().
get
(
2
)
==
null
);
assertTrue
(
c
.
getSeatGroups
().
get
(
3
)
==
null
);
assertTrue
(
c
.
getSeatGroups
().
get
(
1
).
getSeat
(
3
)
==
trainModel
.
getSeats
().
get
(
nSeats
-
1
));
}
private
void
checkSize
(
int
expected
,
Collection
<?>
actualCollection
)
{
assertEquals
(
expected
,
actualCollection
.
size
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment