From 183356a93fc9770501834f0ff1390d5b4a097c84 Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Tue, 23 Jun 2026 14:01:20 +0200 Subject: [PATCH 1/3] BooleanExpressionExtension.cs defined --- .../Extend/BooleanExpressionExtensions.cs | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/SysML2.NET/Extend/BooleanExpressionExtensions.cs b/SysML2.NET/Extend/BooleanExpressionExtensions.cs index 16dc8862..ecced43d 100644 --- a/SysML2.NET/Extend/BooleanExpressionExtensions.cs +++ b/SysML2.NET/Extend/BooleanExpressionExtensions.cs @@ -1,40 +1,31 @@ // ------------------------------------------------------------------------------------------------- // -// -// Copyright (C) 2022-2026 Starion Group S.A. -// -// 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 -// +// +// Copyright (C) 2022-2026 Starion Group S.A. +// +// 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. -// +// // // ------------------------------------------------------------------------------------------------ namespace SysML2.NET.Core.POCO.Kernel.Functions { using System; - using System.Collections.Generic; - - using SysML2.NET.Core.Core.Types; - using SysML2.NET.Core.Root.Namespaces; - using SysML2.NET.Core.POCO.Core.Features; - using SysML2.NET.Core.POCO.Core.Types; - using SysML2.NET.Core.POCO.Kernel.Behaviors; - using SysML2.NET.Core.POCO.Root.Annotations; - using SysML2.NET.Core.POCO.Root.Elements; - using SysML2.NET.Core.POCO.Root.Namespaces; + using System.Diagnostics.CodeAnalysis; /// - /// The class provides extensions methods for - /// the interface + /// The class provides extensions methods for + /// the interface /// internal static class BooleanExpressionExtensions { @@ -42,16 +33,17 @@ internal static class BooleanExpressionExtensions /// Computes the derived property. /// /// - /// The subject + /// The subject /// /// /// the computed result /// - [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [ExcludeFromCodeCoverage] internal static IPredicate ComputePredicate(this IBooleanExpression booleanExpressionSubject) { - throw new NotSupportedException("Create a GitHub issue when this method is required"); + return booleanExpressionSubject == null + ? throw new ArgumentNullException(nameof(booleanExpressionSubject)) + : booleanExpressionSubject.ComputeFunction() as IPredicate; } - } } From f27d513cb5d10111ed3767762a6130bdd40d70e1 Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Tue, 23 Jun 2026 16:23:23 +0200 Subject: [PATCH 2/3] BooleanExpressionExtension.cs test defined --- .../BooleanExpressionExtensionsTestFixture.cs | 31 ++++++++++++++++--- .../Extend/BooleanExpressionExtensions.cs | 2 ++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/SysML2.NET.Tests/Extend/BooleanExpressionExtensionsTestFixture.cs b/SysML2.NET.Tests/Extend/BooleanExpressionExtensionsTestFixture.cs index c1be9b35..909d9b14 100644 --- a/SysML2.NET.Tests/Extend/BooleanExpressionExtensionsTestFixture.cs +++ b/SysML2.NET.Tests/Extend/BooleanExpressionExtensionsTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// Copyright 2022-2026 Starion Group S.A. +// Copyright (C) 2022-2026 Starion Group S.A. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,18 +21,39 @@ namespace SysML2.NET.Tests.Extend { using System; - + using NUnit.Framework; - using SysML2.NET.Core.POCO.Kernel.Functions ; + using SysML2.NET.Core.POCO.Core.Features; + using SysML2.NET.Core.POCO.Kernel.Functions; + using SysML2.NET.Extensions; [TestFixture] public class BooleanExpressionExtensionsTestFixture { [Test] - public void ComputePredicate_ThrowsNotSupportedException() + public void VerifyComputePredicate() { - Assert.That(() => ((IBooleanExpression)null).ComputePredicate(), Throws.TypeOf()); + // Null subject: + Assert.That(() => ((IBooleanExpression)null).ComputePredicate(), Throws.TypeOf()); + + // Empty BooleanExpression: + var emptyBooleanExpression = new BooleanExpression(); + Assert.That(emptyBooleanExpression.ComputePredicate(), Is.Null); + + // Typed by Function, but not Predicate (predicate is a specialization of function): + var nonPredicateBooleanExpression = new BooleanExpression(); + var function = new Function(); + var functionTyping = new FeatureTyping { Type = function }; + nonPredicateBooleanExpression.AssignOwnership(functionTyping); + Assert.That(nonPredicateBooleanExpression.ComputePredicate(), Is.Null); + + // Typed by Predicate: + var predicateBooleanExpression = new BooleanExpression(); + var predicate = new Predicate(); + var predicateTyping = new FeatureTyping { Type = predicate }; + predicateBooleanExpression.AssignOwnership(predicateTyping); + Assert.That(predicateBooleanExpression.ComputePredicate(), Is.SameAs(predicate)); } } } diff --git a/SysML2.NET/Extend/BooleanExpressionExtensions.cs b/SysML2.NET/Extend/BooleanExpressionExtensions.cs index ecced43d..f60aefe5 100644 --- a/SysML2.NET/Extend/BooleanExpressionExtensions.cs +++ b/SysML2.NET/Extend/BooleanExpressionExtensions.cs @@ -41,6 +41,8 @@ internal static class BooleanExpressionExtensions [ExcludeFromCodeCoverage] internal static IPredicate ComputePredicate(this IBooleanExpression booleanExpressionSubject) { + // this method is a specialization of the method function from ExpressionExtensions.cs; + // therefore, just return the function as a predicate; if no function, will return null; return booleanExpressionSubject == null ? throw new ArgumentNullException(nameof(booleanExpressionSubject)) : booleanExpressionSubject.ComputeFunction() as IPredicate; From efeeab429d6aa446845b3a6c2b9665ae4a33eda2 Mon Sep 17 00:00:00 2001 From: TanaseMariusatstarion Date: Tue, 23 Jun 2026 17:01:07 +0200 Subject: [PATCH 3/3] BooleanExpressionExtension.cs correction for multiple types within booleanExpressionSubject --- SysML2.NET/Extend/BooleanExpressionExtensions.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SysML2.NET/Extend/BooleanExpressionExtensions.cs b/SysML2.NET/Extend/BooleanExpressionExtensions.cs index f60aefe5..77b37368 100644 --- a/SysML2.NET/Extend/BooleanExpressionExtensions.cs +++ b/SysML2.NET/Extend/BooleanExpressionExtensions.cs @@ -22,6 +22,7 @@ namespace SysML2.NET.Core.POCO.Kernel.Functions { using System; using System.Diagnostics.CodeAnalysis; + using System.Linq; /// /// The class provides extensions methods for @@ -41,11 +42,9 @@ internal static class BooleanExpressionExtensions [ExcludeFromCodeCoverage] internal static IPredicate ComputePredicate(this IBooleanExpression booleanExpressionSubject) { - // this method is a specialization of the method function from ExpressionExtensions.cs; - // therefore, just return the function as a predicate; if no function, will return null; return booleanExpressionSubject == null ? throw new ArgumentNullException(nameof(booleanExpressionSubject)) - : booleanExpressionSubject.ComputeFunction() as IPredicate; + : booleanExpressionSubject.type.OfType().FirstOrDefault(); } } }