-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco De Salvo
committed
May 27, 2024
1 parent
170064e
commit 9f7c45f
Showing
6 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2012-2024 Marco De Salvo | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using RDFSharp.Model; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Linq; | ||
|
||
namespace RDFSharp.Test.Model | ||
{ | ||
[TestClass] | ||
public class RDFMinExclusiveFacetTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
|
||
public void ShouldCreateMinExclusiveFacet() | ||
{ | ||
RDFMinExclusiveFacet facet = new RDFMinExclusiveFacet(6.145); | ||
|
||
Assert.IsNotNull(facet); | ||
Assert.IsTrue(facet.ExclusiveLowerBound == 6.145d); | ||
Assert.IsTrue(facet.URI.IsBlank); | ||
} | ||
|
||
[TestMethod] | ||
|
||
public void ShouldValidateMinExclusiveFacet() | ||
{ | ||
RDFMinExclusiveFacet facet = new RDFMinExclusiveFacet(6); | ||
|
||
Assert.IsFalse(facet.Validate("-2.0089")); | ||
Assert.IsFalse(facet.Validate("2.047")); | ||
Assert.IsFalse(facet.Validate(null)); | ||
Assert.IsFalse(facet.Validate(string.Empty)); | ||
Assert.IsTrue(facet.Validate("14.5773")); | ||
Assert.IsFalse(facet.Validate("6")); | ||
Assert.IsFalse(facet.Validate("abcdefgh")); | ||
|
||
RDFMinExclusiveFacet facet0 = new RDFMinExclusiveFacet(-12.45); | ||
Assert.IsFalse(facet0.Validate("-16.2442")); | ||
Assert.IsFalse(facet0.Validate("-12.45")); | ||
Assert.IsTrue(facet0.Validate("-12")); | ||
} | ||
|
||
[TestMethod] | ||
|
||
public void ShouldConvertMinExclusiveFacetToGraph() | ||
{ | ||
RDFMinExclusiveFacet facet = new RDFMinExclusiveFacet(6); | ||
RDFGraph graph = facet.ToRDFGraph(); | ||
|
||
Assert.IsNotNull(graph); | ||
Assert.IsTrue(graph.TriplesCount == 1); | ||
Assert.IsTrue(graph.Single().Predicate.Equals(RDFVocabulary.XSD.MIN_EXCLUSIVE)); | ||
Assert.IsTrue(graph.Single().Object.Equals(new RDFTypedLiteral("6", RDFDatatypeRegister.GetDatatype(RDFVocabulary.XSD.DOUBLE.ToString())))); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2012-2024 Marco De Salvo | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
|
||
namespace RDFSharp.Model | ||
{ | ||
/// <summary> | ||
/// RDFMinExclusiveFacet represents a constraint requiring the values of a literal to have a minimum numeric lower bound (excluded) | ||
/// </summary> | ||
public class RDFMinExclusiveFacet : RDFFacet | ||
{ | ||
#region Properties | ||
/// <summary> | ||
/// Minimum numeric lower bound (excluded) required by the facet | ||
/// </summary> | ||
public double ExclusiveLowerBound { get; internal set; } | ||
#endregion | ||
|
||
#region Ctors | ||
/// <summary> | ||
/// Builds a facet requiring the given exclusive lower bound | ||
/// </summary> | ||
public RDFMinExclusiveFacet(double exclusiveLowerBound) | ||
=> ExclusiveLowerBound = exclusiveLowerBound; | ||
#endregion | ||
|
||
#region Methods | ||
/// <summary> | ||
/// Gives a graph representation of the MinExclusive facet | ||
/// </summary> | ||
public override RDFGraph ToRDFGraph() | ||
=> new RDFGraph(new List<RDFTriple>() { | ||
new RDFTriple(URI, RDFVocabulary.XSD.MIN_EXCLUSIVE, new RDFTypedLiteral(Convert.ToString(ExclusiveLowerBound, CultureInfo.InvariantCulture), RDFModelEnums.RDFDatatypes.XSD_DOUBLE)) }); | ||
|
||
/// <summary> | ||
/// Validates the given literal value against the MinExclusive facet | ||
/// </summary> | ||
public override bool Validate(string literalValue) | ||
{ | ||
if (double.TryParse(literalValue, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double parseLiteralValue)) | ||
return parseLiteralValue > ExclusiveLowerBound; | ||
return false; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters