Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Agriterix
simulator
Commits
2247da05
Commit
2247da05
authored
Jul 28, 2021
by
Loris Croce
Browse files
tests for FlowDynamics
parent
1c79a3ce
Pipeline
#38434
passed with stages
in 4 minutes and 31 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/inrae/agriterix/simulator/Simulator.java
View file @
2247da05
...
...
@@ -122,7 +122,7 @@ public class Simulator {
for
(
Class
type
:
new
Class
[]{
Product
.
class
,
Patch
.
class
,
GeoArea
.
class
,
Flow
.
class
,
Livestock
.
class
,
Ratio
.
class
,
Tag
.
class
,
Farmer
.
class
,
Farm
.
class
,
Unit
.
class
,
CulturalPractice
.
class
,
Parameters
.
class
,
Simulator
.
class
,
Product
.
class
,
MarketDynamics
.
class
,
ProductionDynamics
.
class
,
PopulationDynamics
.
class
,
FlowDynamics
.
class
,
Dynamics
.
class
})
{
PopulationDynamics
ByAgeClass
.
class
,
FlowDynamics
.
class
,
Dynamics
.
class
})
{
xstream
.
alias
(
namespace
+
type
.
getSimpleName
(),
type
);
}
// useful w/ xpath
...
...
src/main/java/fr/inrae/agriterix/simulator/dynamics/PopulationDynamicsByAgeClass.java
View file @
2247da05
...
...
@@ -18,7 +18,8 @@ public class PopulationDynamicsByAgeClass extends Dynamics {
public
PopulationDynamicsByAgeClass
()
{
}
public
PopulationDynamicsByAgeClass
(
double
amplitude
,
double
drop_x
,
double
mu
,
double
v
,
double
r_threshold
,
double
r_factor
,
TransmissionStrategy
transmission
)
{
public
PopulationDynamicsByAgeClass
(
double
amplitude
,
double
drop_x
,
double
mu
,
double
v
,
double
r_threshold
,
double
r_factor
,
TransmissionStrategy
transmission
)
{
this
.
amplitude
=
amplitude
;
this
.
drop_x
=
drop_x
;
this
.
mu
=
mu
;
...
...
src/test/java/fr/inrae/agriterix/simulator/DynamicsTest.java
View file @
2247da05
package
fr.inrae.agriterix.simulator
;
import
com.opencsv.CSVReader
;
import
com.opencsv.exceptions.CsvException
;
import
fr.inrae.agriterix.simulator.dynamics.FlowDynamics
;
import
fr.inrae.agriterix.simulator.dynamics.MarketDynamics
;
import
fr.inrae.agriterix.simulator.dynamics.PopulationDynamics
;
import
org.junit.*
;
import
static
org
.
junit
.
Assert
.*;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
DynamicsTest
{
...
...
@@ -37,6 +31,69 @@ public class DynamicsTest {
}
@Test
public
void
testEditInputs
()
{
List
<
Flow
.
Input
>
inputs
=
new
ArrayList
<>();
inputs
.
add
(
new
Flow
.
Input
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
100
f
));
List
<
Product
>
outputs
=
new
ArrayList
<>();
outputs
.
add
(
new
Product
(
"Vin"
,
Unit
.
L
));
Map
<
Product
,
Float
>
required
=
new
HashMap
<>();
required
.
put
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
1
f
);
Map
<
Product
,
Float
>
produced
=
new
HashMap
<>();
produced
.
put
(
new
Product
(
"Vin"
,
Unit
.
L
),
1
f
);
Stocks
stocks
=
new
Stocks
();
Ratio
ratio
=
new
Ratio
(
required
,
produced
);
Flow
flow
=
new
Flow
(
inputs
,
stocks
,
outputs
,
ratio
);
FlowDynamics
flowDynamics
=
new
FlowDynamics
();
flowDynamics
.
initLogger
();
Map
<
String
,
Float
>
edits
=
new
HashMap
<>();
edits
.
put
(
"Raisin"
,
0.5f
);
flowDynamics
.
editInputs
(
0
,
flow
,
edits
);
assertEquals
(
Optional
.
of
(
flow
.
getInputs
().
get
(
0
).
getMaximum
()),
Optional
.
of
(
50
f
));
}
@Test
public
void
testEditProduced
()
{
List
<
Flow
.
Input
>
inputs
=
new
ArrayList
<>();
inputs
.
add
(
new
Flow
.
Input
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
100
f
));
List
<
Product
>
outputs
=
new
ArrayList
<>();
outputs
.
add
(
new
Product
(
"Vin"
,
Unit
.
L
));
Map
<
Product
,
Float
>
required
=
new
HashMap
<>();
required
.
put
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
1
f
);
Map
<
Product
,
Float
>
produced
=
new
HashMap
<>();
produced
.
put
(
new
Product
(
"Vin"
,
Unit
.
L
),
1
f
);
Stocks
stocks
=
new
Stocks
();
Ratio
ratio
=
new
Ratio
(
required
,
produced
);
Flow
flow
=
new
Flow
(
inputs
,
stocks
,
outputs
,
ratio
);
FlowDynamics
flowDynamics
=
new
FlowDynamics
();
flowDynamics
.
initLogger
();
Map
<
String
,
Float
>
edits
=
new
HashMap
<>();
edits
.
put
(
"Vin"
,
0.5f
);
flowDynamics
.
editProduced
(
0
,
flow
,
edits
);
assertEquals
(
Optional
.
of
(
flow
.
getRatio
().
getProduced
().
get
(
new
Product
(
"Vin"
,
Unit
.
L
))),
Optional
.
of
(.
5
f
));
}
@Test
public
void
testEditRequired
()
{
List
<
Flow
.
Input
>
inputs
=
new
ArrayList
<>();
inputs
.
add
(
new
Flow
.
Input
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
100
f
));
List
<
Product
>
outputs
=
new
ArrayList
<>();
outputs
.
add
(
new
Product
(
"Vin"
,
Unit
.
L
));
Map
<
Product
,
Float
>
required
=
new
HashMap
<>();
required
.
put
(
new
Product
(
"Raisin"
,
Unit
.
Kg
),
1
f
);
Map
<
Product
,
Float
>
produced
=
new
HashMap
<>();
produced
.
put
(
new
Product
(
"Vin"
,
Unit
.
L
),
1
f
);
Stocks
stocks
=
new
Stocks
();
Ratio
ratio
=
new
Ratio
(
required
,
produced
);
Flow
flow
=
new
Flow
(
inputs
,
stocks
,
outputs
,
ratio
);
FlowDynamics
flowDynamics
=
new
FlowDynamics
();
flowDynamics
.
initLogger
();
Map
<
String
,
Float
>
edits
=
new
HashMap
<>();
edits
.
put
(
"Raisin"
,
0.5f
);
flowDynamics
.
editRequirements
(
0
,
flow
,
edits
);
assertEquals
(
Optional
.
of
(
flow
.
getRatio
().
getRequired
().
get
(
new
Product
(
"Raisin"
,
Unit
.
Kg
))),
Optional
.
of
(.
5
f
));
}
@Test
public
void
testAllocate
()
{
// debug : String bold = "\033[0;1m";
...
...
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