// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using Deltares.Dam.Data;
namespace Deltares.Standard.Specifications.Tests
{
#region Model
internal class Model
{
private readonly List clusters = new List();
public int Id { get; set; }
public void AddCluster(Cluster cluster)
{
CompositeSpecification clusterValid = new ClusterValidIdSpecification();
ISpecification clusterInCollection = new ClusterInCollection(clusters);
ISpecification validAndNotInCollection = clusterValid.And(clusterInCollection).Not();
if (validAndNotInCollection.IsSatisfiedBy(cluster))
{
clusters.Add(cluster);
Console.WriteLine("Cluster added");
}
else
{
Console.WriteLine("Error adding cluster");
Console.WriteLine(validAndNotInCollection.Description);
}
}
}
internal class ModelUniqueIdSpecification : ParameterSpecification
{
public ModelUniqueIdSpecification(int id) : base(id) {}
public override bool IsSatisfiedBy(Model candidate)
{
return candidate.Id == ParameterValue;
}
}
#endregion
#region Cluster
internal class Cluster
{
public int Id { get; set; }
public List Layers { get; } = new List();
public Layer[] GetLayersBySepcification(ISpecification specification)
{
return Layers.FindAll(specification.IsSatisfiedBy).ToArray();
}
}
internal class ClusterValidIdSpecification : CompositeSpecification
{
public ClusterValidIdSpecification()
{
Description = "Cluster id must be between 0 and 10";
}
public override bool IsSatisfiedBy(Cluster obj)
{
return obj.Id > 0 && obj.Id < 11;
}
}
internal class ClusterInCollection : PredicateSpecification
{
public ClusterInCollection(IEnumerable coll) :
base(x => new List(coll).Exists(y => y.Id == x.Id))
{
Description = "A cluster collection may not contain multiple clusters with the same id";
}
}
#endregion
#region Layer
[Specification(typeof(LayerHasValidTopBottomValues))]
internal class Layer
{
[Specification(typeof(NotNullAndContainsCodeXY))]
public string Name { get; set; }
public int Height { get; set; }
public int Top { get; set; }
public int Bottom { get; set; }
}
internal class NotNullAndContainsCodeXY : PredicateSpecification
{
public NotNullAndContainsCodeXY() : base(x => !string.IsNullOrEmpty(x) && x.Contains("XY"))
{
Description = "The name should contain XY";
}
}
internal class LayerHasValidTopBottomValues : PredicateSpecification
{
public LayerHasValidTopBottomValues()
: base(x => x.Bottom < x.Top)
{
Description = "Top value of layer must be greater then bottom value";
}
}
#endregion
#region Soil
internal class Soil
{
[Minimum(20)] public double GammaWet { get; set; }
[Maximum(-1)] public double GammaDry { get; set; }
}
#endregion
}