SensitivityAnalysisResult { public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); } @JsonCreator  SensitivityAnalysisResult(@JsonProperty("ok") boolean ok,
                                     @JsonProperty("metrics") Map<String, String> metrics,
                                     @JsonProperty("logs") String logs,
                                     @JsonProperty("values") List<SensitivityValue> sensitivityValues,
                                     @JsonProperty("contingenciesValues") Map<String, List<SensitivityValue>> sensitivityValuesContingencies);  SensitivityAnalysisResult(boolean ok,
                                     Map<String, String> metrics,
                                     String logs,
                                     List<SensitivityValue> sensitivityValues); boolean isOk(); Map<String, String> getMetrics(); String getLogs(); Collection<SensitivityValue> getSensitivityValues(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFactor factor); boolean contingenciesArePresent(); Map<String, List<SensitivityValue>> getSensitivityValuesContingencies(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function, String contingencyId); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFactor factor, String contingencyId); static SensitivityAnalysisResult empty();  }
@Test public void getNonExistingSensitivityValueByFunctionAndVariable() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, Collections.emptyMap()); SensitivityFunction wrongFunction = Mockito.mock(SensitivityFunction.class); SensitivityVariable wrongVariable = Mockito.mock(SensitivityVariable.class); exception.expect(NoSuchElementException.class); results.getSensitivityValue(wrongFunction, wrongVariable); }
@Test public void getNonExistingSensitivityValueByFunctionAndVariableContingency() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); Map<String, List<SensitivityValue>> valuesContingency = Collections.singletonMap("Contingency", values); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, valuesContingency); SensitivityFunction wrongFunction = Mockito.mock(SensitivityFunction.class); SensitivityVariable wrongVariable = Mockito.mock(SensitivityVariable.class); exception.expect(NoSuchElementException.class); results.getSensitivityValue(wrongFunction, wrongVariable, "Contingency"); }
@Test public void getNonExistingSensitivityValueByFactor() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, Collections.emptyMap()); SensitivityFactor wrongFactor = Mockito.mock(SensitivityFactor.class); Mockito.when(wrongFactor.getFunction()).thenReturn(Mockito.mock(SensitivityFunction.class)); Mockito.when(wrongFactor.getVariable()).thenReturn(Mockito.mock(SensitivityVariable.class)); exception.expect(NoSuchElementException.class); results.getSensitivityValue(wrongFactor); }
@Test public void getNonExistingSensitivityValueByFactorContingency() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); Map<String, List<SensitivityValue>> valuesContingency = Collections.singletonMap("Contingency", values); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, valuesContingency); SensitivityFactor wrongFactor = Mockito.mock(SensitivityFactor.class); Mockito.when(wrongFactor.getFunction()).thenReturn(Mockito.mock(SensitivityFunction.class)); Mockito.when(wrongFactor.getVariable()).thenReturn(Mockito.mock(SensitivityVariable.class)); exception.expect(NoSuchElementException.class); results.getSensitivityValue(wrongFactor, "Contingency"); }
@Test public void getSensitivityValue() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, Collections.emptyMap()); assertSame(factorOk, results.getSensitivityValue(factorOk.getFunction(), factorOk.getVariable()).getFactor()); assertSame(factorNok, results.getSensitivityValue(factorNok.getFunction(), factorNok.getVariable()).getFactor()); assertSame(factorOk, results.getSensitivityValue(factorOk).getFactor()); assertSame(factorNok, results.getSensitivityValue(factorNok).getFactor()); }
@Test public void getSensitivityValueContingency() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); Map<String, List<SensitivityValue>> valuesContingency = Collections.singletonMap("Contingency", values); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, valuesContingency); assertSame(factorOk, results.getSensitivityValue(factorOk.getFunction(), factorOk.getVariable(), "Contingency").getFactor()); assertSame(factorNok, results.getSensitivityValue(factorNok.getFunction(), factorNok.getVariable(), "Contingency").getFactor()); assertSame(factorOk, results.getSensitivityValue(factorOk, "Contingency").getFactor()); assertSame(factorNok, results.getSensitivityValue(factorNok, "Contingency").getFactor()); }