C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Test_Perspective.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5using AnalyzeRe;
8
9#if MSTEST
10using Microsoft.VisualStudio.TestTools.UnitTesting;
11#elif NUNIT
12using NUnit.Framework;
13using TestClass = NUnit.Framework.TestFixtureAttribute;
14using TestMethod = NUnit.Framework.TestAttribute;
15using TestCategory = NUnit.Framework.CategoryAttribute;
16#endif
17
19{
21 [TestClass]
23 {
24 private const string Category = "Test_Perspective";
25
26 #region Test Helper Methods
28 public static readonly Perspective.Base[] AllPerspectiveValues = Enum<Perspective.Base>.Values.ToArray();
29
31 public static readonly Perspective.Base[] CombinablePerspectiveValues = AllPerspectiveValues.Except(new[]
32 {
33 // Loss Gross cannot be combined with any other perspective.
34 Perspective.Base.LossGross,
35#pragma warning disable 618
36 // Do not include the legacy LossNetOfAggregateTerms value because it is already a "Combined" perspective.
37 // While it can be further combined with Premium,RPremium,RBrokerage, it should not be combined with any others.
38 Perspective.Base.LossNetOfAggregateTerms
39#pragma warning restore 618
40 }).ToArray();
41
42 // A list of all perspectives that can be combined with NetLoss
44 .Except(new[] { Perspective.Base.NetLoss }).ToArray();
45
47 public static IEnumerable<Perspective> TestPerspectives =>
48 // The list should include every perspective on its own
50 // We add a list of "NetLoss" perspectives, with each possible modifier on its own
51 .Concat(NetPerspectiveModifiers.Select(p => Perspective.LossNetOf(p)))
52 // We will also test "NetLoss" with every other perspective also included
54
56 [Obsolete("Used to test legacy perspectives")]
57 public static IEnumerable<Perspective> LegacyTestPerspectives
58 {
59 get
60 {
62 foreach (bool prem in new List<bool> { true, false })
63 foreach (bool reinstPrem in new List<bool> { true, false })
64 foreach (bool reinstBrok in new List<bool> { true, false })
65 yield return Perspective.LossNetOfAggregateTermsAnd(prem, reinstPrem, reinstBrok);
66 }
67 }
68
71 Reflection.Resolve(analysisProfile).default_perspective ??
72#pragma warning disable 618
73 // TODO ARE-6645: This should be removed once API changes to analysis profiles have been updated
75#pragma warning restore 618
76
78 public void AssertEquivalence(Perspective first, Perspective second)
79 {
80 string message = $"Expected {first} and {second} to match";
81 Assert.AreEqual(first.GetHashCode(), second.GetHashCode(), message + ", but their hash codes do not.");
82 Assert.IsTrue(first.Equals(second), message);
83 Assert.IsTrue(second.Equals(first), message);
84 Assert.AreEqual(first, second, message);
85 // String representations aren't guaranteed to be equivalent (because the original order or arguments is maintained)
86 if (!first.ToString().Equals(second.ToString()))
87 Console.WriteLine($"Note: {first} and {second} are equivalent but their string representations are not.");
88 }
89
91 public void AssertInequivalence(Perspective first, Perspective second)
92 {
93 string message = $"Expected {first} and {second} to differ";
94 Assert.IsFalse(first.Equals(second), message);
95 Assert.IsFalse(second.Equals(first), message);
96 Assert.AreNotEqual(first, second, message);
97 Assert.AreNotEqual(first.ToString(), second.ToString(), message + ", but their string representations do not.");
98 // Note: It isn't technically a requirement for hash codes to never collide,
99 // but since there are a finite number of combinations possible, we should
100 // be able to provide a hash algorithm where hashes do not in fact collide.
101 Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode(), message + ", but their hash codes do not.");
102 }
103 #endregion Test Helper Methods
104
105 [TestMethod, TestCategory(Category)]
107 {
108 // Test two singletons
113 // And non-equivalence
120 // Assert that singletons are equal to perspectives constructed implicitly from strings
122 AssertEquivalence(Perspective.ReinstatementBrokerage, "ReinstatementBrokerage");
123 AssertEquivalence(Perspective.ReinstatementPremium, "ReinstatementPremium");
125 // Assert that singletons are equal to perspectives build with factory method
129 Perspective.FromEnum(Perspective.Base.ReinstatementBrokerage));
131 Perspective.FromEnum(Perspective.Base.ReinstatementPremium));
134 // Assert a perspective with options is equal from a string or parameters
135 AssertEquivalence(Perspective.LossNetOf(Perspective.Base.Premium, Perspective.Base.ReinstatementBrokerage),
136 "NetLoss,Premium,ReinstatementBrokerage");
137 }
138
139 [TestMethod, TestCategory(Category)]
141 {
143 Perspective.Base.ReinstatementBrokerage, Perspective.Base.FixedExpense);
144 Perspective second = Perspective.FromString("NetLoss,Premium,ReinstatementBrokerage,FixedExpense");
145 Perspective third = "Premium,NetLoss,FixedExpense,ReinstatementBrokerage";
146 AssertEquivalence(first, second);
147 AssertEquivalence(first, third);
148 AssertEquivalence(second, third);
149
150 // Now ensure these perspectives aren't treated as equivalent.
151 Perspective different = "NetLoss,Premium,ReinstatementPremium,FixedExpense";
152 AssertInequivalence(first, different);
153 AssertInequivalence(second, different);
154 AssertInequivalence(third, different);
155 }
156
157 [TestMethod, TestCategory(Category)]
175
176 #region Legacy Perspective Tests
177 [TestMethod, TestCategory(Category)]
178 [Obsolete("Tests legacy perspective construction")]
180 {
182 // And non-equivalence
186 // Assert that singletons are equal to perspectives constructed implicitly from strings
187 Assert.AreEqual(Perspective.LossNetOfAggregateTerms, "LossNetOfAggregateTerms");
188 // Assert that singletons are equal to perspectives build with constructor
189 Assert.AreEqual(Perspective.LossNetOfAggregateTerms,
190 new Perspective(Perspective.Base.LossNetOfAggregateTerms));
191 // Assert a perspective with options is equal from a string or parameters
192 Assert.AreEqual(Perspective.LossNetOfAggregateTermsAnd(true, false, true),
193 "LossNetOfAggregateTerms[Premium,ReinstatementBrokerage]");
194 }
195
196 [TestMethod, TestCategory(Category)]
197 [Obsolete("Tests legacy perspective construction")]
199 {
200 // Note: we no longer prevent the user from creating invalid perspectives, so these all pass.
201 Perspective _ = new Perspective(Perspective.Base.LossGross, new[] { Perspective.Option.Premium });
202 _ = new Perspective(Perspective.Base.ReinstatementPremium, new[] { Perspective.Option.Premium });
203 _ = new Perspective("ReinstatementBrokerage[Premium]");
204 _ = new Perspective("LossNetOfAggregateTerms[BadOption]");
205 _ = new Perspective("LossNetOfOccurrenceTerms");
206 _ = new Perspective("Junk,,,");
207 }
208
209 [TestMethod, TestCategory(Category)]
210 [Obsolete("Tests legacy perspective construction")]
212 {
215 AssertEquivalence(perspective, Perspective.FromEnum(Perspective.Base.LossNetOfAggregateTerms));
217 // The following works because the string value can be implicitly converted to a perspective
218 AssertEquivalence(perspective, "LossNetOfAggregateTerms");
219 Assert.IsTrue(perspective.Equals("LossNetOfAggregateTerms"));
220
221 Perspective legacyConstruction = Perspective.LossNetOfAggregateTermsAnd(false, false, false);
222 Assert.AreEqual(legacyConstruction, legacyConstruction.ToString());
223 Assert.AreEqual(legacyConstruction, "LossNetOfAggregateTerms");
224 Assert.AreEqual(legacyConstruction, Perspective.FromEnum(Perspective.Base.LossNetOfAggregateTerms));
225 Assert.AreEqual(legacyConstruction, new Perspective(Perspective.Base.LossNetOfAggregateTerms));
226 Assert.AreEqual(Perspective.LossNetOfAggregateTermsAnd(false, false, false).GetHashCode(),
227 new Perspective(Perspective.Base.LossNetOfAggregateTerms).GetHashCode());
228 Assert.AreEqual(Perspective.LossNetOfAggregateTermsAnd(true, false, true),
229 Perspective.LossNetOfAggregateTermsAnd(true, false, true).ToString());
230 }
231
232 [TestMethod, TestCategory(Category)]
233 [Obsolete("Tests legacy perspective construction")]
235 {
236 Perspective first = Perspective.LossNetOfAggregateTermsAnd(true, reinstatement_brokerage: true);
237 Perspective second = new Perspective("LossNetOfAggregateTerms[Premium,ReinstatementBrokerage]");
238 Perspective third = "LossNetOfAggregateTerms[ReinstatementBrokerage,Premium]";
239 AssertEquivalence(first, second);
240 AssertEquivalence(first, third);
241 AssertEquivalence(second, third);
242
243 // Now ensure these perspectives aren't treated as equivalent.
244 Perspective different = "LossNetOfAggregateTerms[ReinstatementPremium,Premium]";
245 AssertInequivalence(first, different);
246 AssertInequivalence(second, different);
247 AssertInequivalence(third, different);
248 }
249 #endregion Legacy Perspective Tests
250 }
251}
static Reflection Reflection
Shared instance of a class for generating random resources.
void AssertEquivalence(Perspective first, Perspective second)
Assert that two perspectives constructed differently are treated as equivalent in every way.
static readonly Perspective.Base[] AllPerspectiveValues
A list of all perspective values.
static IEnumerable< Perspective > LegacyTestPerspectives
Create a list of distinct perspectives to test.
static IEnumerable< Perspective > TestPerspectives
Create a list of distinct perspectives to test.
static Perspective GetDefaultPerspectiveForAnalysisProfile(IReference< AnalysisProfile > analysisProfile)
Get the AnalysisProfile.default_perspective of the analysis profile.
void AssertInequivalence(Perspective first, Perspective second)
Assert that two perspectives constructed differently are treated as equivalent in every way.
static readonly Perspective.Base[] CombinablePerspectiveValues
A list of all perspectives that can be combined with one-another.
The loss perspective determines what factors to include when computing a distribution.
static readonly Perspective ReinstatementBrokerage
Construct a distribution from the structure's net reinstatement brokerages.
static Perspective FromEnum(Base perspective)
Returns the appropriate singleton for the Base perspective given.
static readonly Perspective SlidingScaleCommission
Report on the structure's Fees.FixedExpense fees.
static readonly Perspective LossGross
Construct a distribution from the structure's gross losses.
static Perspective LossNetOf(params Base[] perspectives)
A convenience static method, similar to the other static singletons, which constructs a complex persp...
override string ToString()
Perspective string is just the class name.
static readonly Perspective ProportionalExpense
Report on the structure's Fees.ProportionalExpense fees.
bool Equals(Perspective other)
Determine whether the two perspectives are equivalent.
static readonly Perspective FixedExpense
Report on the structure's Fees.FixedExpense fees.
static readonly Perspective NetLoss
Construct a distribution from the structure's net losses.
override int GetHashCode()
Serves as a hash function for a particular type.
static readonly Perspective LossNetOfAggregateTerms
The legacy perspective value indicating "net loss" - but this includes fee record types as well.
static readonly Perspective NoClaimsBonus
Report on the structure's Fees.FixedExpense fees.
Base
The set of available values and RecordTypes that can be used to construct a distribution or metrics r...
static Perspective FromString(string perspectiveString)
Implicit converter that allows automatically converting a string into a perspective,...
static Perspective LossNetOfAggregateTermsAnd(bool premium=false, bool reinstatement_premium=false, bool reinstatement_brokerage=false)
Constructs a legacy LossNetOfAggregateTerms[X,Y,Z] perspective, where you can specify which values to...
static readonly Perspective Premium
Report on the structure's premium only.
static readonly Perspective ReinstatementPremium
Construct a distribution from the structure's net reinstatement premiums.
static readonly Perspective ProfitCommission
Report on the structure's Fees.FixedExpense fees.
static Perspective FromEnums(params Base[] perspectives)
Construct a new Perspective that should include the specified Base perspective value or values.
Helper class for extending the functionality of the static Enumclass with compile-time-type-specific ...
Definition Enum.cs:11
Base interface for all reference entities.