Skip to content

Commit c4ae2a9

Browse files
authored
Merge pull request #131 from USACE-RMC/testFix
Test fix successful with all warnings extinguished locally and unit testing all passing matched with GH checks.
2 parents 3d206f9 + da5175e commit c4ae2a9

165 files changed

Lines changed: 1262 additions & 1035 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Numerics/Data/Interpolation/CubicSpline.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
using System;
32-
using System.Collections.Generic;
33-
3431
namespace Numerics.Data
3532
{
3633
/// <summary>
@@ -78,7 +75,7 @@ public CubicSpline(IList<double> xValues, IList<double> yValues, SortOrder sortO
7875
/// <summary>
7976
/// Stores the array of second derivatives.
8077
/// </summary>
81-
private double[] y2;
78+
private double[] y2 = Array.Empty<double>();
8279

8380
/// <summary>
8481
/// Auxiliary routine to set the second derivatives. If you make changes to the x- or y-values, then you need to call this routine afterwards.

Numerics/Data/Paired Data/OrderedPairedData.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Data;
3636
using System.Linq;
3737
using System.Xml.Linq;
38+
using System.Xml.Serialization;
3839
using Numerics.Distributions;
3940

4041
namespace Numerics.Data
@@ -102,7 +103,7 @@ public class OrderedPairedData : IList<Ordinate>, INotifyCollectionChanged
102103
private bool _strictY;
103104
private SortOrder _orderX;
104105
private SortOrder _orderY;
105-
private List<Ordinate> _ordinates;
106+
private readonly List<Ordinate> _ordinates;
106107

107108
/// <inheritdoc/>
108109
public event NotifyCollectionChangedEventHandler? CollectionChanged;
@@ -265,20 +266,24 @@ public OrderedPairedData(XElement el)
265266
{
266267
// Get Strictness
267268
bool strict = false;
268-
if (el.Attribute(nameof(StrictX)) != null) { bool.TryParse(el.Attribute(nameof(StrictX)).Value, out strict); }
269+
var strictXAttr = el.Attribute(nameof(StrictX));
270+
if (strictXAttr != null) { bool.TryParse(strictXAttr.Value, out strict); }
269271
StrictX = strict;
270272

271273
strict = false;
272-
if (el.Attribute(nameof(StrictY)) != null) { bool.TryParse(el.Attribute(nameof(StrictY)).Value, out strict); }
274+
var strictYAttr = el.Attribute(nameof(StrictY));
275+
if (strictYAttr != null) { bool.TryParse(strictYAttr.Value, out strict); }
273276
StrictY = strict;
274277

275278
// Get Order
276279
SortOrder order = SortOrder.None;
277-
if (el.Attribute(nameof(OrderX)) != null) { Enum.TryParse(el.Attribute(nameof(OrderX)).Value, out order); }
280+
var orderXAttr = el.Attribute(nameof(OrderX));
281+
if (orderXAttr != null) { Enum.TryParse(orderXAttr.Value, out order); }
278282
OrderX = order;
279283

280284
order = SortOrder.None;
281-
if (el.Attribute(nameof(OrderY)) != null) { Enum.TryParse(el.Attribute(nameof(OrderY)).Value, out order); }
285+
var orderYAttr = el.Attribute(nameof(OrderY));
286+
if (orderYAttr != null) { Enum.TryParse(orderYAttr.Value, out order); }
282287
OrderY = order;
283288

284289
// Ordinates
@@ -1432,15 +1437,14 @@ private double TriangleArea(Ordinate point1, Ordinate point2, Ordinate point3)
14321437
/// and number of points in the search region.</returns>
14331438
public OrderedPairedData LangSimplify(double tolerance, int lookAhead)
14341439
{
1435-
if (_ordinates == null | lookAhead <= 1 | tolerance <= 0)
1436-
return this;
1440+
if (lookAhead <= 1 | tolerance <= 0) { return this; }
14371441

14381442
List<Ordinate> ordinates = new List<Ordinate>();
14391443

14401444
int count = _ordinates.Count;
14411445
int offset;
1442-
if (lookAhead > count - 1)
1443-
lookAhead = count - 1;
1446+
if (lookAhead > count - 1) { lookAhead = count - 1; }
1447+
14441448
ordinates.Add(_ordinates[0]);
14451449

14461450
for (int i = 0; i < count; i++)

Numerics/Data/Paired Data/Ordinate.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ public Ordinate(double xValue, double yValue)
7979
public Ordinate(XElement xElement)
8080
{
8181
double x = 0, y = 0;
82-
83-
if (xElement.Attribute(nameof(X)) != null) double.TryParse(xElement.Attribute(nameof(X))?.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out x);
84-
if (xElement.Attribute(nameof(Y)) != null) double.TryParse(xElement.Attribute(nameof(Y))?.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out y);
82+
var xAttribute = xElement.Attribute(nameof(X));
83+
var yAttribute = xElement.Attribute(nameof(Y));
84+
if (xAttribute != null) double.TryParse(xAttribute.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out x);
85+
if (yAttribute != null) double.TryParse(yAttribute.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out y);
8586
X = x;
8687
Y = y;
8788
IsValid = true;

Numerics/Data/Paired Data/UncertainOrderedPairedData.cs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Collections;
3333
using System.Collections.Generic;
3434
using System.Collections.Specialized;
35+
using System.Data;
3536
using System.Globalization;
3637
using System.Linq;
3738
using System.Xml.Linq;
@@ -171,7 +172,7 @@ public SortOrder OrderY
171172
/// <summary>
172173
/// Handles the event of CollectionChanged
173174
/// </summary>
174-
public event NotifyCollectionChangedEventHandler CollectionChanged;
175+
public event NotifyCollectionChangedEventHandler? CollectionChanged;
175176

176177
#endregion
177178

@@ -243,7 +244,12 @@ public UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX,
243244
_orderY = yOrder;
244245
_uncertainOrdinates = new List<UncertainOrdinate>(data.Count);
245246
for (int i = 0; i < data.Count; i++)
246-
_uncertainOrdinates.Add(new UncertainOrdinate(data[i].X, data[i].Y.Clone()));
247+
{
248+
var o = data[i];
249+
UnivariateDistributionBase? yValue = o.Y?.Clone();
250+
if (yValue is not null) { _uncertainOrdinates.Add(new UncertainOrdinate(o.X, yValue)); }
251+
}
252+
247253
Validate();
248254
}
249255

@@ -266,8 +272,12 @@ private UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX
266272
_orderY = yOrder;
267273
_uncertainOrdinates = new List<UncertainOrdinate>(data.Count);
268274
for (int i = 0; i < data.Count; i++)
269-
_uncertainOrdinates.Add(new UncertainOrdinate(data[i].X, data[i].Y.Clone()));
270-
275+
{
276+
var o = data[i];
277+
UnivariateDistributionBase? yValue = o.Y?.Clone();
278+
if (yValue is not null) { _uncertainOrdinates.Add(new UncertainOrdinate(o.X, yValue)); }
279+
}
280+
271281
_isValid = dataValid;
272282
}
273283

@@ -277,34 +287,44 @@ private UncertainOrderedPairedData(IList<UncertainOrdinate> data, bool strictOnX
277287
/// <param name="el">The XElement the UncertainOrderPairedData object is being created from.</param>
278288
public UncertainOrderedPairedData(XElement el)
279289
{
290+
var strictX = el.Attribute("X_Strict");
280291
// Get Order
281-
if (el.Attribute("X_Strict") != null)
282-
bool.TryParse(el.Attribute("X_Strict").Value, out _strictX);
283-
if (el.Attribute("Y_Strict") != null)
284-
bool.TryParse(el.Attribute("Y_Strict").Value, out _strictY);
292+
if (strictX != null) { bool.TryParse(strictX.Value, out _strictX); }
293+
294+
var strictY = el.Attribute("Y_Strict");
295+
if (strictY != null) { bool.TryParse(strictY.Value, out _strictY); }
296+
285297
// Get Strictness
286-
if (el.Attribute("X_Order") != null)
287-
Enum.TryParse(el.Attribute("X_Order").Value, out _orderX);
288-
if (el.Attribute("Y_Order") != null)
289-
Enum.TryParse(el.Attribute("Y_Order").Value, out _orderY);
298+
var orderX = el.Attribute("X_Order");
299+
if (orderX != null) { Enum.TryParse(orderX.Value, out _orderX); }
300+
301+
var orderY = el.Attribute("Y_Order");
302+
if (orderY != null) { Enum.TryParse(orderY.Value, out _orderY); }
303+
290304
// Distribution type
291305
Distribution = UnivariateDistributionType.Deterministic;
292-
if (el.Attribute("Distribution") != null)
306+
var distributionAttr = el.Attribute("Distribution");
307+
if (distributionAttr != null)
293308
{
294309
var argresult = Distribution;
295-
Enum.TryParse(el.Attribute("Distribution").Value, out argresult);
310+
Enum.TryParse(distributionAttr.Value, out argresult);
296311
Distribution = argresult;
297312
}
298313
// new prop
299-
300-
if (el.Attribute(nameof(AllowDifferentDistributionTypes)) != null)
314+
var allowDiffAtr = el.Attribute(nameof(AllowDifferentDistributionTypes));
315+
if (allowDiffAtr != null)
301316
{
302-
bool.TryParse(el.Attribute(nameof(AllowDifferentDistributionTypes)).Value, out _allowDifferentDistributionTypes);
317+
bool.TryParse(allowDiffAtr.Value, out _allowDifferentDistributionTypes);
303318
// Get Ordinates
304319
var curveEl = el.Element("Ordinates");
305320
_uncertainOrdinates = new List<UncertainOrdinate>();
306-
foreach (XElement ord in curveEl.Elements(nameof(UncertainOrdinate)))
307-
_uncertainOrdinates.Add(new UncertainOrdinate(ord));
321+
322+
if (curveEl != null)
323+
{
324+
foreach (XElement ord in curveEl.Elements(nameof(UncertainOrdinate)))
325+
_uncertainOrdinates.Add(new UncertainOrdinate(ord));
326+
}
327+
308328
}
309329
else
310330
{
@@ -315,15 +335,19 @@ public UncertainOrderedPairedData(XElement el)
315335
{
316336
foreach (XElement o in curveEl.Elements("Ordinate"))
317337
{
318-
double.TryParse(o.Attribute("X").Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var xout);
319-
xData.Add(xout);
338+
var xAttr = o.Attribute("X");
339+
if ( xAttr != null && double.TryParse(xAttr.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var xout)) { xData.Add(xout); }
340+
else { xData.Add(0.0); }
341+
320342
var dist = UnivariateDistributionFactory.CreateDistribution(Distribution);
321343
var props = dist.GetParameterPropertyNames;
322344
var paramVals = new double[(props.Count())];
345+
323346
for (int i = 0; i < props.Count(); i++)
324347
{
325-
double.TryParse(o.Attribute(props[i]).Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result);
326-
paramVals[i] = result;
348+
var pAttr = o.Attribute(props[i]);
349+
if ( pAttr != null && double.TryParse(pAttr.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { paramVals[i] = result; }
350+
else { paramVals[i] = 0.0; }
327351
}
328352

329353
dist.SetParameters(paramVals);
@@ -488,7 +512,14 @@ public List<string> GetErrors()
488512
{
489513
if (left._uncertainOrdinates[i].X != right._uncertainOrdinates[i].X)
490514
return false;
491-
if (left._uncertainOrdinates[i].Y == right._uncertainOrdinates[i].Y == false)
515+
516+
var leftY = left._uncertainOrdinates[i].Y;
517+
var rightY = right._uncertainOrdinates[i].Y;
518+
if (leftY is null && rightY is null)
519+
continue;
520+
if (leftY is null || rightY is null)
521+
return false;
522+
if (!leftY.Equals(rightY))
492523
return false;
493524
}
494525
return true;
@@ -510,7 +541,7 @@ public List<string> GetErrors()
510541
/// </summary>
511542
/// <param name="obj">The object to compare with the current object.</param>
512543
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
513-
public override bool Equals(object obj)
544+
public override bool Equals(object? obj)
514545
{
515546
if (obj is UncertainOrderedPairedData other)
516547
{

0 commit comments

Comments
 (0)