2using System.Collections.Generic;
14using Microsoft.VisualStudio.TestTools.UnitTesting;
19using TestCategory =
NUnit.Framework.CategoryAttribute;
33 AddCommonTestInitializeAction(() =>
42 #region Set Up and Configuration
43 private const string TypeName =
"OptimizationView";
52 WaitForOptimizationResult(
posted);
57 AddCommonTestInitializeAction(() =>
61 #endregion Set Up and Configuration
71 base.Test_Resource_GET_AllPropertiesRecognized();
75 #region analysis_profile
96 #endregion analysis_profile
122 #endregion iterations
124 #region population_size
149 #endregion population_size
151 #region custom_parameters
175 #region Discretization
204 #endregion Discretization
206 #region Return_Period
235 #endregion Return_Period
236 #endregion custom_parameters
268 modified.
domains.First().min = 0.5;
269 modified.
domains.First().max = 0.4;
286 modified.
domains.First().allow_exclude =
true;
308 modified.
domains.Add(
new DomainEntry { layer = layer.AsReference, min = 0, max = 1 });
326 modified.
domains.Add(
new DomainEntry { layer = layer.AsReference, min = 0, max = 1 });
332 #region CreatedAndModified
336 POST_ThenDoAction(TestResource,
posted =>
338 Assert.IsNotNull(
posted.created,
"Expected a 'created' date to be assigned.");
339 Assert.IsNotNull(
posted.modified,
"Expected a 'modified' date to be assigned.");
342 #endregion CreatedAndModified
344 #region target_currency
350 #endregion target_currency
372 string message =
$"Waited {ex.TimeWaited} seconds for " +
373 "the optimization job to complete, but it never did.\n";
377 message = message + Environment.NewLine +
ex;
398 "Expected at least one candidate in the results.");
401 Assert.IsNotNull(result.
objectives,
"First candidate's objective results were null");
406 [
Obsolete(
"2018-04-23: This tests an obsolete feature that will be removed in the future.")]
419 Assert.IsNotNull(result,
"optimization_view result was null");
420 Assert.IsTrue(result.
candidates.Count >= 1,
"Expected at least one candidate");
456 Assert.IsNotNull(
first.index,
"Expected the candidate index to be set.");
457 Assert.AreEqual(result.items.First().index,
first.index);
478 Assert.IsTrue(result.meta.total_count >= 1,
"Expected at least one candidate");
505 Assert.IsFalse(String.IsNullOrWhiteSpace(result),
"optimization_view csv result was empty");
518 layer = Samples.Layer_CatXL.Unposted.Change(l => l.limit,
519 new MonetaryUnit(100,
"EUR")).Post().ToReference(),
527 #region Sensitivity Analysis
536 Assert.IsNotNull(
sa,
"Sensitivity Analysis cannot be null");
537 Assert.IsNotNull(
sa.sensitivities,
"Analysis should contain list of sensitivities");
538 Assert.IsTrue(
sa.sensitivities.Count > 0,
539 "Number of sensitivities for the test should be at least 1");
541 "Number of sensitivities should be equal to the number of domains");
544 Assert.IsNotNull(
s.min,
"Min value should exist");
545 Assert.IsNotNull(
s.max,
"Max value should exist");
546 Assert.IsNotNull(
s.mean,
"Mean value should exist");
547 Assert.IsNotNull(
s.ref_id,
"Reference ID should exist");
548 Assert.IsNotNull(
s.normalized_standard_deviation,
"Standard deviation should exist");
549 Assert.IsNotNull(
s.normalized_interquartile_range,
"Interquartile range should exist");
550 Assert.IsNotNull(
s.hist,
"Histogram should exist");
551 Assert.AreEqual(20,
s.hist.Count,
"Histogram should have 20 bins");
564 Assert.IsNotNull(
sa,
"Sensitivity Analysis cannot be null");
565 Assert.IsNotNull(
sa.sensitivities,
"Analysis should contain list of sensitivities");
566 Assert.IsTrue(
sa.sensitivities.Count > 0,
567 "Number of sensitivities for the test should be at least 1");
569 "Number of sensitivities should be equal to the number of domains");
572 Assert.IsNotNull(
s.min,
"Min value should exist");
573 Assert.IsNotNull(
s.max,
"Max value should exist");
574 Assert.IsNotNull(
s.mean,
"Mean value should exist");
575 Assert.IsNotNull(
s.ref_id,
"Reference ID should exist");
576 Assert.IsNotNull(
s.normalized_standard_deviation,
"Standard deviation should exist");
577 Assert.IsNotNull(
s.normalized_interquartile_range,
"Interquartile range should exist");
578 Assert.IsNotNull(
s.hist,
"Histogram should exist");
579 Assert.AreEqual(20,
s.hist.Count,
"Histogram should have 20 bins");
593 Assert.IsNotNull(
sa,
"Sensitivity Analysis cannot be null");
594 Assert.IsNotNull(
sa.sensitivities,
"Analysis should contain list of sensitivities");
595 Assert.AreEqual(
sa.sensitivities.Count, 0,
"Number of sensitivities for this test should be 0");
598 #endregion Sensitivity Analysis
Tests for a stored resource collection which do not require an instance of that resource to be define...
Exposes sample resource objects, with built-in methods for injecting dependencies.
List< IInjectableResource< ILayer > > AllSaveableLayerTypesTestList
A list of one of each type of layer that can be POSTed. Layer types that cannot be posted on their ow...
static string Valid_NonExistant_UUID
List< IInjectableResource< ILayer > > AllLayerTypesTestList
A list of one of each type of layer.
IInjectableResource< OptimizationView > OptimizationView_Simulated
override IResourceCollection< OptimizationView > collection_source
TestSuite_OptimizationView_Base()
override bool PUT_Allowed
override void AdditionalValidResourceTests(OptimizationView posted)
Ensure that any optimization_views posted by this test library complete successfully.
override bool DELETE_Allowed
void Test_OptimizationView_POST_Iterations_TooHigh()
void Test_OptimizationView_GET_Results_Succeeds()
void Test_OptimizationView_POST_Domain_Layer_InvalidTypes()
void Test_OptimizationView_POST_Iterations_Minimum()
void Test_OptimizationView_GET_LegacyResults_Succeeds()
void Test_OptimizationView_POST_CustomParameters_Empty()
void Test_OptimizationView_GET_Results_Candidate_PortfolioView_Succeeds()
void Test_OptimizationView_GET_Results_Mixed_Currencies_Fails()
void Test_OptimizationView_POST_Domain_MinAndMax_Limit()
void Test_OptimizationView_POST_PopulationSize_Minimum()
void Test_OptimizationView_POST_CustomParameters_MixedTypes()
void Test_OptimizationView_POST_CustomParameters_Null()
void Test_OptimizationView_POST_CustomParameters_Discretization_Maximum()
void Test_OptimizationView_POST_CustomParameters_Return_Period_TooLow()
void Test_OptimizationView_POST_AnalysisProfile_Reference_NonExistantId()
void Test_OptimizationView_POST_CustomParameters_Return_Period_Maximum()
static readonly HashSet< Type > UnsupportedOptimizationLayerTypes
The layer types which aren't supported by optimization views.
void Test_OptimizationView_POST_CustomParameters_Return_Period_Minimum()
void Test_OptimizationView_POST_Domain_Layer_ValidTypes()
void Test_OptimizationView_POST_Domain_Null()
void Test_OptimizationView_GET_Sensitivity_Analysis_Succeeds_With_Candidates()
override void Test_Resource_POST_CreatedAndModified()
void Test_OptimizationView_POST_AnalysisProfile_Reference_EmptyStringId()
override void Test_Resource_GET_AllPropertiesRecognized()
void Test_OptimizationView_POST_Iterations_TooLow()
void Test_OptimizationView_POST_Domain_AllowExclude()
void Test_OptimizationView_POST_CustomParameters_Discretization_TooLow()
void Test_OptimizationView_GET_Results_Candidates_Succeeds()
void Test_OptimizationView_POST_Domain_InvalidLayerId()
void Test_OptimizationView_POST_CustomParameters_Return_Period_TooHigh()
TestSuite_OptimizationView()
void Test_OptimizationView_POST_AnalysisProfile_Reference_NullId()
override IInjectableResource< OptimizationView > TestInjectableResource
void Test_OptimizationView_POST_Domain_Empty()
void Test_OptimizationView_POST_Domain_MaxLessThanMin()
static readonly PollingOptions OptimizationPolling
void Test_OptimizationView_GET_Sensitivity_Analysis_Succeeds_No_Candidates()
void Test_OptimizationView_GET_InitialPortfolio_Succeeds()
void Test_OptimizationView_GET_Results_Summary_Succeeds()
void Test_OptimizationView_POST_TargetCurrency_Null()
void Test_OptimizationView_POST_CustomParameters_Discretization_Minimum()
void Test_OptimizationView_GET_Sensitivity_Analysis_Succeeds_Non_Existing_Candidates()
void Test_OptimizationView_POST_PopulationSize_TooLow()
void Test_OptimizationView_POST_AnalysisProfile_Null()
void Test_OptimizationView_POST_PopulationSize_TooHigh()
Retrieve settings from environment variables if they exist, or the project settings file otherwise.
static int OPTIMIZATION_TIMEOUTS
Amount of time to wait for optimization engine requests to complete (in milliseconds).
Generic Unit test implementations that will test REST methods on arbitrary resources.
Class used in unit tests to mark tests as skipped by using Assert.Inconclusive() method.
static void Indefinitely(string ticket=null)
Skip the specified test.
Describes a collection of resources which can be listed.
API methods / requests made available to the user.
static int DefaultRequestTimeout
The default timeout used for all simple server requests, in milliseconds.
static int DefaultRequestTimeoutCollections
The default timeout used when requesting a resource collection from the server, in milliseconds.
static readonly ResourceCollection< OptimizationView > OptimizationViews
The collection of OptimizationViews on the server.
Acts as a replacement for IAPIResourceView.back_allocations. Computes the proportion of some sink str...
A "delayed payment" payment pattern models claims being paid in instalments at fixed delays after the...
Filter is like a layer whose 'terms' are to filter events out of the loss sources....
A "delayed payment" payment pattern models claims being paid in instalments at specific dates followi...
A structure that can be used to change the currency of a loss stream from one currency to another at ...
Representation of an Industry Loss Warranty, which is a layer that triggers a payout (currently expre...
The LossRank layer allows one to select a subset of occurrences in a trial year based on the relative...
Allows one or more source layers or layer_views to be attached as loss sources to some other layer de...
The No Claims Bonus applies a payout to trials which contain no losses. (i.e. when there are no occur...
Representation of a Surplus Share contract.
Surfaces the value-allocator specialty structure (which is treated as a "layer definition" by the API...
Optional parameters which can be specified for all metrics requests.
static new MetricsOptions Default
The default metrics request options used when none are specified.
The structure returned when requesting Tail Metrics for a view.
Thrown when a request requires additional time to complete, but it exceeds the time we are willing to...
The structure returned by the results endpoint that contains candidates solutions to the optimization...
List< Candidate > candidates
The list of candidates this result consists of.
A candidate is a potential solution to the optimization problem.
A structure indicating the min/max share constraint for a layer.
Object to map metrics on the initial portfolio.
Dictionary< string, double > objectives
The set of objective function results for this candidate.
Representation of a set of Optimization Parameters.
Dictionary< string, object > custom_parameters
A key/value pair dictionary of additional parameters taken by the optimization function.
List< DomainEntry > domains
The list of layers to be optimized and their min/max constraints.
One layer sensitivity parameters.
Sensitivity analysis for the optimization view.
Determines the behaviour of the API when automatically retrying a request whose result is not yet rea...
Represents the Analysis of a Portfolio.
TaskStatus
The status of a data upload which may be in progress.