Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Materials plugin unit tests #11

Merged
merged 30 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
da69662
unit tests for materials action support
bischoffz Nov 23, 2022
46e1fd9
unit tests for testbatchconinfo
bischoffz Nov 23, 2022
0389732
Merge branch 'dev' of https://github.com/HHS/ASPR-8 into materials-pl…
bischoffz Dec 1, 2022
6af387e
unit tests for materials producer prop id
bischoffz Dec 1, 2022
19376e8
unit tests for materials producer prop def init
bischoffz Dec 1, 2022
2ee5124
wip unit tests for materials producer const data
bischoffz Dec 1, 2022
863123d
unit tests for materials producer const data
bischoffz Dec 3, 2022
7e351dd
fix unit test names
bischoffz Dec 3, 2022
fa4bd27
stubbing out test methods
bischoffz Dec 5, 2022
7a624fd
unit tests for batch prop def init
bischoffz Dec 7, 2022
f807763
unit tests for batch const info
bischoffz Dec 7, 2022
2bab2d2
unit tests for materials producer prop def event
bischoffz Dec 7, 2022
57072a7
unit tests for materials producer add event
bischoffz Dec 7, 2022
26c82e9
unit tests for material id add event
bischoffz Dec 7, 2022
80c2717
unit tests for batch prop def event
bischoffz Dec 7, 2022
1e4b7e3
unit tests for stage report
bischoffz Dec 7, 2022
7fba6ae
unit tests for materials producer resource report
bischoffz Dec 7, 2022
94b4d6a
unit tests for materials producer prop report
bischoffz Dec 7, 2022
b9c42e8
unit tests for batch status report
bischoffz Dec 7, 2022
a3483e1
unit test for convertStageToResource
bischoffz Dec 7, 2022
3e9a173
fix compile error
bischoffz Dec 7, 2022
4db81d1
remove implement event
bischoffz Dec 14, 2022
524d874
unit tests for materials data manager
bischoffz Dec 14, 2022
980e34c
Merge branch 'dev' of https://github.com/HHS/ASPR-8 into materials-pl…
bischoffz Dec 14, 2022
c4c4db2
add missing annotation
bischoffz Dec 14, 2022
b8174d6
materials data manager unit test fixes
bischoffz Dec 15, 2022
ec4fc22
remove explicit types from Pair<>
bischoffz Dec 15, 2022
052e232
use builder chaining
bischoffz Dec 15, 2022
621ed97
use random prop value
bischoffz Dec 15, 2022
1dcf052
Merge branch 'dev' of https://github.com/HHS/ASPR-8 into materials-pl…
bischoffz Dec 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void init(final ActorContext actorContext) {
}
}

public void handleMaterialsProducerAdditionEvent(ActorContext actorContext, MaterialsProducerAdditionEvent materialsProducerAdditionEvent) {
private void handleMaterialsProducerAdditionEvent(ActorContext actorContext, MaterialsProducerAdditionEvent materialsProducerAdditionEvent) {
MaterialsProducerId materialsProducerId = materialsProducerAdditionEvent.getMaterialsProducerId();
ResourcesDataManager resourcesDataManager = actorContext.getDataManager(ResourcesDataManager.class);
MaterialsDataManager materialsDataManager = actorContext.getDataManager(MaterialsDataManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1697,8 +1697,6 @@ private void destroyBatch(final BatchId batchId) {
* property definition</li>
* <li>{@linkplain MaterialsError#OFFERED_STAGE_UNALTERABLE} if
* the batch in on an offered stage</li>
* <li>{@linkplain MaterialsError#MATERIALS_OWNERSHIP} if the
* requesting agent is not the owning materials producer</li>
*
*
*
Expand Down Expand Up @@ -1797,8 +1795,6 @@ private void validateMaterialProducerPropertyValueNotNull(final Object propertyV
* is null</li>
* <li>{@linkplain MaterialsError#UNKNOWN_BATCH_ID} if the batch
* id is unknown</li>
* <li>{@linkplain MaterialsError#MATERIALS_OWNERSHIP} if the
* requesting agent is not the owning materials producer</li>
* <li>{@linkplain MaterialsError#BATCH_NOT_STAGED} if the batch
* is not staged</li>
* <li>{@linkplain MaterialsError#OFFERED_STAGE_UNALTERABLE } if
Expand Down Expand Up @@ -1855,8 +1851,6 @@ private void validateBatchIsStaged(final BatchId batchId) {
* <li>{@linkplain MaterialsError#BATCH_STAGED_TO_DIFFERENT_OWNER}
* if batch and stage do not have the same owning materials
* producer</li>
* <li>{@linkplain MaterialsError#MATERIALS_OWNERSHIP} if the
* requesting agent is not the owning material producer</li>
*
*
*/
Expand Down Expand Up @@ -2153,8 +2147,6 @@ public void setStageOfferState(StageId stageId, boolean offer) {
* is null</li>
* <li>{@linkplain MaterialsError#UNKNOWN_STAGE_ID} if stage id
* is unknown</li>
* <li>{@linkplain MaterialsError#MATERIALS_OWNERSHIP} if the
* requesting agent is not the owning materials producer</li>
* <li>{@linkplain MaterialsError#OFFERED_STAGE_UNALTERABLE} if
* the stage is offered</li>
* <li>{@linkplain MaterialsError#NON_FINITE_MATERIAL_AMOUNT} if
Expand Down Expand Up @@ -2236,8 +2228,6 @@ public BatchId convertStageToBatch(StageId stageId, MaterialId materialId, doubl
* id is unknown</li>
* <li>{@linkplain MaterialsError#OFFERED_STAGE_UNALTERABLE} if
* the stage is offered</li>
* <li>{@linkplain MaterialsError#MATERIALS_OWNERSHIP} if the
* requesting agent is not the owning materials producer</li>
* <li>{@linkplain ResourceError#NEGATIVE_RESOURCE_AMOUNT} if
* the the resource amount is negative</li>
* <li>{@linkplain ResourceError#RESOURCE_ARITHMETIC_EXCEPTION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static class Builder {

private Data data = new Data();

private Builder(){}

private void validate() {
if (data.materialsProducerId == null) {
throw new ContractException(MaterialsError.NULL_MATERIALS_PRODUCER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MaterialsProducerPropertyDefinitionEvent(MaterialsProducerPropertyId mate
/**
* Returns the property id of the added property definition
*/
public MaterialsProducerPropertyId getPersonPropertyId() {
public MaterialsProducerPropertyId getProducerPropertyId() {
return materialsProducerPropertyId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static Builder builder() {
public static class Builder {
private Data data = new Data();

private Builder() {}

private void validate() {
if (data.materialsProducerId == null) {
throw new ContractException(MaterialsError.NULL_MATERIALS_PRODUCER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
*/
public class MaterialsActionSupport {

private MaterialsActionSupport(){}

/**
* Creates an action plugin with an agent that will execute the given
* consumer at time 0. The action plugin and the remaining arguments are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public class TestBatchConstructionInfo {

private TestBatchConstructionInfo(){}

public static BatchConstructionInfo getBatchConstructionInfo(MaterialsProducerId materialsProducerId, MaterialId materialId, double amount, RandomGenerator randomGenerator) {
BatchConstructionInfo.Builder builder = //
BatchConstructionInfo .builder()//
Expand Down
4 changes: 2 additions & 2 deletions gcm4/src/test/java/nucleus/AT_EventFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testGetFunctionValuePairs() {
.addFunctionValuePair(xFunction, 2)//
.build();
functionValuePairs = eventFilter.getFunctionValuePairs();
expectedFunctionValuePairs.add(new Pair<IdentifiableFunction<?>, Object>(xFunction, 2));
expectedFunctionValuePairs.add(new Pair<>(xFunction, 2));
assertNotNull(functionValuePairs);
assertEquals(expectedFunctionValuePairs, functionValuePairs);

Expand All @@ -110,7 +110,7 @@ public void testGetFunctionValuePairs() {
.addFunctionValuePair(yFunction, 3.0)//
.build();
functionValuePairs = eventFilter.getFunctionValuePairs();
expectedFunctionValuePairs.add(new Pair<IdentifiableFunction<?>, Object>(yFunction, 3.0));
expectedFunctionValuePairs.add(new Pair<>(yFunction, 3.0));
assertNotNull(functionValuePairs);
assertEquals(expectedFunctionValuePairs, functionValuePairs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testGetPropertyValues() {
GroupId groupId = new GroupId(10000 + i);
for (int j = 0; j < 3; j++) {
String value = Integer.toString(randomGenerator.nextInt(100));
Pair<GroupId, String> propertyValue = new Pair<GroupId, String>(groupId, value);
Pair<GroupId, String> propertyValue = new Pair<>(groupId, value);
expectedListOfPropertyValues.add(propertyValue);
definitionInitializationBuilder.addPropertyValue(groupId, value);
}
Expand Down Expand Up @@ -328,7 +328,7 @@ public void testAddPropertyValue() {
GroupId groupId = new GroupId(10000 + i);
for (int j = 0; j < 3; j++) {
String value = Integer.toString(randomGenerator.nextInt(100));
Pair<GroupId, String> propertyValue = new Pair<GroupId, String>(groupId, value);
Pair<GroupId, String> propertyValue = new Pair<>(groupId, value);
expectedListOfPropertyValues.add(propertyValue);
definitionInitializationBuilder.addPropertyValue(groupId, value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plugins.materials.actors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -36,7 +37,9 @@
import plugins.reports.support.ReportItem.Builder;
import plugins.reports.support.SimpleReportId;
import plugins.stochastics.StochasticsDataManager;
import tools.annotations.UnitTag;
import tools.annotations.UnitTest;
import tools.annotations.UnitTestConstructor;
import tools.annotations.UnitTestMethod;

@UnitTest(target = BatchStatusReport.class)
Expand All @@ -54,16 +57,15 @@ private ReportItem getReportItemFromBatch(ActorContext agentContext, BatchId bat
stageString = optionalStageId.get().toString();
}

List<Object> elements = new ArrayList<>();
List<Object> elements = new ArrayList<>();

elements.add(agentContext.getTime());
elements.add(batchId);
elements.add(batchProducer);
elements.add(stageString);
elements.add(batchMaterialId);
elements.add(amount);



for (MaterialId materialId : materialsDataManager.getMaterialIds()) {
boolean matchingMaterial = batchMaterialId.equals(materialId);
Set<BatchPropertyId> batchPropertyIds = materialsDataManager.getBatchPropertyIds(materialId);
Expand All @@ -75,15 +77,22 @@ private ReportItem getReportItemFromBatch(ActorContext agentContext, BatchId bat
}
}
}

ReportItem reportItem = getReportItem(elements);



return reportItem;
}

@Test
@UnitTestMethod(name = "init", args = {ActorContext.class})
@UnitTestConstructor(args = { ReportId.class })
public void testConstructor() {
BatchStatusReport report = new BatchStatusReport(REPORT_ID);

assertNotNull(report);
}

@Test
@UnitTestMethod(name = "init", args = { ActorContext.class }, tags = { UnitTag.INCOMPLETE })
public void testInit() {

Set<ReportItem> expectedReportItems = new LinkedHashSet<>();
Expand All @@ -103,7 +112,8 @@ public void testInit() {
for (int i = 0; i < 20; i++) {
TestMaterialId materialId = TestMaterialId.getRandomMaterialId(randomGenerator);
double amount = randomGenerator.nextDouble();
BatchConstructionInfo batchConstructionInfo = TestBatchConstructionInfo.getBatchConstructionInfo(testMaterialsProducerId, materialId, amount, randomGenerator);
BatchConstructionInfo batchConstructionInfo = TestBatchConstructionInfo
.getBatchConstructionInfo(testMaterialsProducerId, materialId, amount, randomGenerator);
BatchId batchId = materialsDataManager.addBatch(batchConstructionInfo);
expectedReportItems.add(getReportItemFromBatch(c, batchId));
}
Expand All @@ -118,7 +128,8 @@ public void testInit() {
RandomGenerator randomGenerator = stochasticsDataManager.getRandomGenerator();

for (TestMaterialId testMaterialId : TestMaterialId.values()) {
List<BatchId> batches = materialsDataManager.getInventoryBatchesByMaterialId(testMaterialsProducerId, testMaterialId);
List<BatchId> batches = materialsDataManager
.getInventoryBatchesByMaterialId(testMaterialsProducerId, testMaterialId);

if (batches.size() > 1) {
for (int i = 0; i < batches.size(); i++) {
Expand Down Expand Up @@ -166,7 +177,8 @@ public void testInit() {

for (BatchId batchId : inventoryBatches) {
TestMaterialId materialId = materialsDataManager.getBatchMaterial(batchId);
TestBatchPropertyId propertyId = TestBatchPropertyId.getRandomMutableBatchPropertyId(materialId, randomGenerator);
TestBatchPropertyId propertyId = TestBatchPropertyId.getRandomMutableBatchPropertyId(materialId,
randomGenerator);
Object value = propertyId.getRandomPropertyValue(randomGenerator);
materialsDataManager.setBatchPropertyValue(batchId, propertyId, value);
expectedReportItems.add(getReportItemFromBatch(c, batchId));
Expand Down Expand Up @@ -219,17 +231,17 @@ public void testInit() {

TestPluginData testPluginData = pluginBuilder.build();
Plugin testPlugin = TestPlugin.getTestPlugin(testPluginData);
//Set<ReportItem> actualReportItems = MaterialsActionSupport.testConsumers(8914112012010329946L, testPlugin, new BatchStatusReport(REPORT_ID)::init);
Set<ReportItem> actualReportItems = MaterialsActionSupport.testConsumers(2819236410498978100L, testPlugin, new BatchStatusReport(REPORT_ID)::init);

// Set<ReportItem> actualReportItems =
// MaterialsActionSupport.testConsumers(8914112012010329946L, testPlugin, new
// BatchStatusReport(REPORT_ID)::init);
Set<ReportItem> actualReportItems = MaterialsActionSupport.testConsumers(2819236410498978100L, testPlugin,
new BatchStatusReport(REPORT_ID)::init);

assertEquals(expectedReportItems, actualReportItems);
}

private static ReportItem getReportItem(List<Object> values) {
Builder builder = ReportItem.builder();
builder.setReportId(REPORT_ID);
builder.setReportHeader(REPORT_HEADER);
Builder builder = ReportItem.builder().setReportId(REPORT_ID).setReportHeader(REPORT_HEADER);
for (Object value : values) {
builder.addValue(value);
}
Expand All @@ -242,16 +254,17 @@ private static ReportItem getReportItem(List<Object> values) {

private static ReportHeader getReportHeader() {

ReportHeader.Builder builder = ReportHeader .builder()//
.add("time")//
.add("batch")//
.add("materials_producer")//
.add("stage")//
.add("material")//
.add("amount");//
ReportHeader.Builder builder = ReportHeader.builder()//
.add("time")//
.add("batch")//
.add("materials_producer")//
.add("stage")//
.add("material")//
.add("amount");//

for (TestMaterialId testMaterialId : TestMaterialId.values()) {
for (TestBatchPropertyId testBatchPropertyId : TestBatchPropertyId.getTestBatchPropertyIds(testMaterialId)) {
for (TestBatchPropertyId testBatchPropertyId : TestBatchPropertyId
.getTestBatchPropertyIds(testMaterialId)) {
builder.add(testMaterialId + "." + testBatchPropertyId);
}
}
Expand Down
Loading