Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
vadere
vadere
Commits
52bb68bb
Commit
52bb68bb
authored
Sep 17, 2016
by
Jakob Schöttl
Browse files
Refactor tests
parent
2641d902
Changes
3
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/tests/org/vadere/simulator/models/seating/TestChooseSeat.java
View file @
52bb68bb
...
...
@@ -44,15 +44,11 @@ public class TestChooseSeat {
final
int
nTrials
=
1000
;
TallySheet
<
Seat
>
tallySheet
=
runChooseSeat
(
nTrials
);
final
double
[]
fractions
=
new
AttributesSeating
().
getSeatChoice0
();
double
sum
=
0
;
for
(
double
d
:
fractions
)
{
sum
+=
d
;
}
final
double
[]
probabilities
=
FractionProbabilityNormalization
.
normalize
(
new
AttributesSeating
().
getSeatChoice0
());
for
(
int
i
=
0
;
i
<
tallySheet
.
getKeys
().
size
();
i
++)
{
Seat
s
=
seatGroup
.
getSeat
(
i
);
assertEquals
(
fractions
[
i
]
/
sum
,
(
double
)
tallySheet
.
getCount
(
s
)
/
nTrials
,
0.05
);
assertEquals
(
probabilities
[
i
]
,
(
double
)
tallySheet
.
getCount
(
s
)
/
nTrials
,
0.05
);
}
}
...
...
VadereSimulator/tests/org/vadere/simulator/models/seating/TestChooseSeatGroup.java
View file @
52bb68bb
...
...
@@ -3,10 +3,10 @@ package org.vadere.simulator.models.seating;
import
static
org
.
junit
.
Assert
.*;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.stream.Collectors
;
import
org.apache.commons.math3.util.Pair
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.vadere.simulator.models.seating.trainmodel.Compartment
;
...
...
@@ -16,6 +16,7 @@ import org.vadere.state.attributes.models.AttributesSeating;
import
org.vadere.state.attributes.scenario.AttributesAgent
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.util.data.TallySheet
;
import
org.vadere.util.test.FractionProbabilityNormalization
;
import
org.vadere.util.test.StatisticalTestCase
;
public
class
TestChooseSeatGroup
{
...
...
@@ -117,17 +118,11 @@ public class TestChooseSeatGroup {
}
private
double
[]
getSeatGroupPersonCountProbabilities
()
{
final
List
<
Pair
<
Boolean
,
Double
>>
probabilities
=
new
AttributesSeating
().
getSeatGroupChoice
();
final
Pair
<
Boolean
,
Double
>
pair
=
probabilities
.
get
(
0
);
assert
pair
.
getFirst
()
==
true
;
final
Pair
<
Boolean
,
Double
>
otherPair
=
probabilities
.
get
(
1
);
assert
otherPair
.
getFirst
()
==
false
;
double
p1
=
pair
.
getSecond
();
double
p2
=
otherPair
.
getSecond
();
final
double
sum
=
p1
+
p2
;
p1
/=
sum
;
p2
/=
sum
;
final
Map
<
Boolean
,
Double
>
probabilities
=
FractionProbabilityNormalization
.
normalize
(
new
AttributesSeating
().
getSeatGroupChoice
());
double
p1
=
probabilities
.
get
(
true
);
double
p2
=
probabilities
.
get
(
false
);
double
[]
ps
=
{
p1
,
p2
,
p2
*
p2
,
p2
*
p2
*
p2
};
return
ps
;
}
...
...
VadereUtils/src/org/vadere/util/test/FractionProbabilityNormalization.java
View file @
52bb68bb
...
...
@@ -25,5 +25,19 @@ public class FractionProbabilityNormalization {
return
map
;
}
public
static
double
[]
normalize
(
double
[]
fractions
)
{
double
sum
=
0
;
for
(
double
d
:
fractions
)
{
sum
+=
d
;
}
double
[]
result
=
new
double
[
fractions
.
length
];
for
(
int
i
=
0
;
i
<
result
.
length
;
i
++)
{
result
[
i
]
=
fractions
[
i
]
/
sum
;
}
return
result
;
}
}
Write
Preview
Supports
Markdown
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