Commit 2247da05 authored by Loris Croce's avatar Loris Croce
Browse files

tests for FlowDynamics

parent 1c79a3ce
Pipeline #38434 passed with stages
in 4 minutes and 31 seconds
...@@ -122,7 +122,7 @@ public class Simulator { ...@@ -122,7 +122,7 @@ public class Simulator {
for (Class type : new Class[]{Product.class, Patch.class, GeoArea.class, Flow.class, Livestock.class, 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, Ratio.class, Tag.class, Farmer.class, Farm.class, Unit.class, CulturalPractice.class, Parameters.class,
Simulator.class, Product.class, MarketDynamics.class, ProductionDynamics.class, Simulator.class, Product.class, MarketDynamics.class, ProductionDynamics.class,
PopulationDynamics.class, FlowDynamics.class, Dynamics.class}) { PopulationDynamicsByAgeClass.class, FlowDynamics.class, Dynamics.class}) {
xstream.alias(namespace + type.getSimpleName(), type); xstream.alias(namespace + type.getSimpleName(), type);
} }
// useful w/ xpath // useful w/ xpath
......
...@@ -18,7 +18,8 @@ public class PopulationDynamicsByAgeClass extends Dynamics { ...@@ -18,7 +18,8 @@ public class PopulationDynamicsByAgeClass extends Dynamics {
public PopulationDynamicsByAgeClass() { 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.amplitude = amplitude;
this.drop_x = drop_x; this.drop_x = drop_x;
this.mu = mu; this.mu = mu;
......
package fr.inrae.agriterix.simulator; package fr.inrae.agriterix.simulator;
import com.opencsv.CSVReader; import fr.inrae.agriterix.simulator.dynamics.FlowDynamics;
import com.opencsv.exceptions.CsvException;
import fr.inrae.agriterix.simulator.dynamics.MarketDynamics; import fr.inrae.agriterix.simulator.dynamics.MarketDynamics;
import fr.inrae.agriterix.simulator.dynamics.PopulationDynamics;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class DynamicsTest { public class DynamicsTest {
...@@ -37,6 +31,69 @@ 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), 100f));
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), 1f);
Map<Product, Float> produced = new HashMap<>();
produced.put(new Product("Vin", Unit.L), 1f);
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(50f));
}
@Test
public void testEditProduced() {
List<Flow.Input> inputs = new ArrayList<>();
inputs.add(new Flow.Input(new Product("Raisin", Unit.Kg), 100f));
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), 1f);
Map<Product, Float> produced = new HashMap<>();
produced.put(new Product("Vin", Unit.L), 1f);
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(.5f));
}
@Test
public void testEditRequired() {
List<Flow.Input> inputs = new ArrayList<>();
inputs.add(new Flow.Input(new Product("Raisin", Unit.Kg), 100f));
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), 1f);
Map<Product, Float> produced = new HashMap<>();
produced.put(new Product("Vin", Unit.L), 1f);
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(.5f));
}
@Test @Test
public void testAllocate() { public void testAllocate() {
// debug : String bold = "\033[0;1m"; // debug : String bold = "\033[0;1m";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment