-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Assert.Not. Integration tests added. Assert tests fixed
- Loading branch information
Showing
7 changed files
with
204 additions
and
9 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/SemanticAssertions.IntegrationTests/Asserts/Default/Async/AssertNotTest.cs
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,15 @@ | ||
using SemanticAssertions.IntegrationTests.Asserts.Shared; | ||
using SemanticAssertions.Providers; | ||
using Xunit.Abstractions; | ||
|
||
namespace SemanticAssertions.IntegrationTests.Asserts.Default.Async; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
public class AssertNotShould : AssertNotTestBase | ||
// ReSharper restore ClassNeverInstantiated.Global | ||
{ | ||
public AssertNotShould(ITestOutputHelper output) : base(output) | ||
{ | ||
Configuration.Current.AddAssertProvider(new DefaultAssertProvider()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/SemanticAssertions.IntegrationTests/Asserts/SemanticKernel/Async/AssertNotTest.cs
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,15 @@ | ||
using SemanticAssertions.IntegrationTests.Asserts.Shared; | ||
using SemanticAssertions.Providers; | ||
using Xunit.Abstractions; | ||
|
||
namespace SemanticAssertions.IntegrationTests.Asserts.SemanticKernel.Async; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
public class AssertNotShould : AssertNotTestBase | ||
// ReSharper restore ClassNeverInstantiated.Global | ||
{ | ||
public AssertNotShould(ITestOutputHelper output) : base(output) | ||
{ | ||
Configuration.Current.AddAssertProvider(new SKAssertProvider()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/SemanticAssertions.IntegrationTests/Asserts/SemanticKernelCosine/Async/AssertNotTest.cs
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,15 @@ | ||
using SemanticAssertions.IntegrationTests.Asserts.Shared; | ||
using SemanticAssertions.Providers; | ||
using Xunit.Abstractions; | ||
|
||
namespace SemanticAssertions.IntegrationTests.Asserts.SemanticKernelCosine.Async; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
public class AssertNotShould : AssertNotTestBase | ||
// ReSharper restore ClassNeverInstantiated.Global | ||
{ | ||
public AssertNotShould(ITestOutputHelper output) : base(output) | ||
{ | ||
Configuration.Current.AddAssertProvider(new SKCosineAssertProvider()); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/SemanticAssertions.IntegrationTests/Asserts/Shared/AssertNotTestBase.cs
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,93 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using SemanticAssertions.Abstractions.Diagnostics; | ||
using Xunit.Abstractions; | ||
|
||
namespace SemanticAssertions.IntegrationTests.Asserts.Shared; | ||
|
||
public abstract class AssertNotTestBase | ||
{ | ||
protected AssertNotTestBase(ITestOutputHelper output) | ||
{ | ||
var logger = new XunitLogger(output); | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true) | ||
.AddJsonFile(path: "testsettings.development.json", optional: true, reloadOnChange: true) | ||
.AddEnvironmentVariables() | ||
.AddUserSecrets<AssertNotTestBase>() | ||
.Build(); | ||
|
||
Configuration.Current | ||
.AddAzureTextCompletion( | ||
configuration.GetValue<string>("AzureOpenAI:ChatDeploymentName"), | ||
configuration.GetValue<string>("AzureOpenAI:Endpoint"), | ||
configuration.GetValue<string>("AzureOpenAI:ApiKey")) | ||
.AddAzureTextEmbeddingGeneration( | ||
configuration.GetValue<string>("AzureOpenAI:TextEmbeddingsDeploymentName"), | ||
configuration.GetValue<string>("AzureOpenAI:Endpoint"), | ||
configuration.GetValue<string>("AzureOpenAI:ApiKey")) | ||
.WithLoggerFactory(logger); | ||
} | ||
|
||
[Fact] | ||
public async Task throw_exception_when_texts_have_a_similarity_greater_than_08() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreSimilar( | ||
"El Teide tiene 3718 metros", | ||
"El Teide, que se encuentra en la isla de Tenerife en España, tiene una altura de aproximadamente 3718 metros sobre el nivel del mar. Es el pico más alto de España y uno de los volcanes más altos del mundo si se mide desde su base en el lecho oceánico.", | ||
0.8)); | ||
|
||
Assert.IsType<SemanticAssertionsException>(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task not_throw_exception_when_texts_have_a_similarity_less_than_08() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreSimilar( | ||
"Nueva York está en USA", | ||
"El Teide, que se encuentra en la isla de Tenerife en España, tiene una altura de aproximadamente 3718 metros sobre el nivel del mar. Es el pico más alto de España y uno de los volcanes más altos del mundo si se mide desde su base en el lecho oceánico.", | ||
0.8)); | ||
|
||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task throw_exception_when_texts_are_similar() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreSimilar( | ||
"El Teide tiene 3718 metros", | ||
"El Teide, que se encuentra en la isla de Tenerife en España, tiene una altura de aproximadamente 3718 metros sobre el nivel del mar. Es el pico más alto de España y uno de los volcanes más altos del mundo si se mide desde su base en el lecho oceánico.")); | ||
|
||
Assert.IsType<SemanticAssertionsException>(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task not_throw_exception_when_texts_are_not_similar() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreSimilar( | ||
"Nueva York está en USA", | ||
"El Teide, que se encuentra en la isla de Tenerife en España, tiene una altura de aproximadamente 3718 metros sobre el nivel del mar. Es el pico más alto de España y uno de los volcanes más altos del mundo si se mide desde su base en el lecho oceánico.")); | ||
|
||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task throw_exception_when_texts_are_in_same_language() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreInSameLanguage( | ||
"Esto es un texto en castellano", | ||
"Esto es otro texto que no debería lanzar excepción porque está en el mismo idioma")); | ||
|
||
Assert.IsType<SemanticAssertionsException>(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task not_throw_exception_when_texts_are_in_different_languages() | ||
{ | ||
var exception = await Record.ExceptionAsync(() => Async.Assert.Not.AreInSameLanguage( | ||
"Esto es un texto en castellano", | ||
"This text must be raise an exception because it is in a different language")); | ||
|
||
Assert.Null(exception); | ||
} | ||
} |
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,58 @@ | ||
using SemanticAssertions.Abstractions.Diagnostics; | ||
// ReSharper disable MemberHidesStaticFromOuterClass | ||
|
||
namespace SemanticAssertions.Async; | ||
|
||
public static partial class Assert | ||
{ | ||
public static class Not | ||
{ | ||
#pragma warning disable S3218 | ||
public static async Task AreSimilar(string expected, string actual) | ||
#pragma warning restore S3218 | ||
{ | ||
try | ||
{ | ||
await Assert.AreSimilar(expected, actual); | ||
} | ||
catch (SemanticAssertionsException) | ||
{ | ||
return; | ||
} | ||
|
||
throw new SemanticAssertionsException($"Strings are similar"); | ||
} | ||
|
||
#pragma warning disable S3218 | ||
public static async Task AreSimilar(string expected, string actual, double similarityThreshold) | ||
#pragma warning restore S3218 | ||
{ | ||
try | ||
{ | ||
await Assert.AreSimilar(expected, actual, similarityThreshold); | ||
} | ||
catch (SemanticAssertionsException) | ||
{ | ||
return; | ||
} | ||
|
||
throw new SemanticAssertionsException($"Strings are similar. Max similarity: {similarityThreshold}."); | ||
} | ||
|
||
#pragma warning disable S3218 | ||
public static async Task AreInSameLanguage(string expected, string actual) | ||
#pragma warning restore S3218 | ||
{ | ||
try | ||
{ | ||
await Assert.AreInSameLanguage(expected, actual); | ||
} | ||
catch (SemanticAssertionsException) | ||
{ | ||
return; | ||
} | ||
|
||
throw new SemanticAssertionsException($"The {nameof(actual)} value is in same language as {nameof(expected)} value."); | ||
} | ||
} | ||
} |
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