diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 7dc4f94875..5997d9aca1 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -12,7 +12,7 @@ ML.NET is a cross-platform, open-source machine learning framework for .NET. It
- .NET SDK version selected by `global.json`
- Build system: Microsoft Arcade SDK (`eng/common/`)
-- Test framework: xUnit (with `AwesomeAssertions`, `Xunit.Combinatorial`)
+- Test framework: xUnit (with `Xunit.Combinatorial`)
- Native dependencies: MKL, OpenMP, libmf, oneDNN
- Major dependencies: TorchSharp, ONNX Runtime, TensorFlow, LightGBM
- Central package management: `Directory.Packages.props`
@@ -136,7 +136,7 @@ public class MyFeatureTests : TestDataPipeBase
Name test classes as `{Feature}Tests`, test methods as PascalCase descriptive names (e.g., `RandomizedPcaTrainerBaselineTest`). Do not use `Test_` prefixes or `_Should_` patterns.
-Use `Assert.*` (xUnit) or `AwesomeAssertions` for fluent assertions. Do not use `Assert.That` (NUnit style).
+Use the built-in `Assert.*` (xUnit) assertions. Do not use `Assert.That` (NUnit style) or additional assertion libraries.
Test data: use `Microsoft.ML.TestDatabases` package or files in `test/data/`, referenced via `GetDataPath("filename")` from the base class. Baseline output comparison uses files in `test/BaselineOutput/`. Update baselines carefully since they are the source of truth for output format stability.
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 8a582c516b..72046ff675 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -69,7 +69,6 @@
-
diff --git a/docs/specs/ML.Net Sweepable API.md b/docs/specs/ML.Net Sweepable API.md
index fe0a3e2be1..528ef51460 100644
--- a/docs/specs/ML.Net Sweepable API.md
+++ b/docs/specs/ML.Net Sweepable API.md
@@ -7,6 +7,8 @@ Search space defines a range of hyper-parameter for tuner to search from. Sweepa
via attribute
```csharp
+using Xunit;
+
public class Option
{
[Range(2, 32768, init: 2, logBase: true)]
@@ -31,17 +33,19 @@ var ss = new SearchSpace();
var parameter = ss.SampleFromFeatureSpace(new []{0,0,0,0,0,0});
// auto-binding
-parameter.WindowSize.Should().Be(2);
-parameter.SeriesLength.Should().Be(2);
-parameter.UseSoftmax.Should().BeTrue();
-parameter.AnotherOption.WindowSize.Should().Be(2);
+Assert.Equal(2, parameter.WindowSize);
+Assert.Equal(2, parameter.SeriesLength);
+Assert.True(parameter.UseSoftmax);
+Assert.Equal(2, parameter.AnotherOption.WindowSize);
// search space can also map parameter back to feature space
-ss.MappingToFeatureSpace(parameter).Should().BeEquivalantTo(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+Assert.Equivalent(new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, ss.MappingToFeatureSpace(parameter), strict: true);
```
or correspondingly, via scratch
``` csharp
+using Xunit;
+
var ss = new SearchSpace();
ss.Add("WindowSize", new UniformIntOption(2, 32768, true, 2));
ss.Add("SeriesLength", new ChoiceOption(2,3,4));
@@ -51,13 +55,13 @@ ss.Add("AnotherOption", ss.Clone());
var parameter = ss.SampleFromFeatureSpace(new []{0,0,0,0,0,0});
// auto-binding doesn't exist for scratch api
-parameter["WindowSize"].AsType.Should().Be(2);
-parameter["SeriesLength"].AsType.Should().Be(2);
-parameter["UseSoftmax"].AsType.Should().BeTrue();
-parameter["AnotherOption"]["WindowSize"].AsType.Should().Be(2);
+Assert.Equal(2, parameter["WindowSize"].AsType());
+Assert.Equal(2, parameter["SeriesLength"].AsType());
+Assert.True(parameter["UseSoftmax"].AsType());
+Assert.Equal(2, parameter["AnotherOption"]["WindowSize"].AsType());
// search space can also map parameter back to feature space
-ss.MappingToFeatureSpace(parameter).Should().BeEquivalantTo(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+Assert.Equivalent(new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, ss.MappingToFeatureSpace(parameter), strict: true);
```
Currently, in order to make auto-binding work, there's a limitation on the parameter type that can be added to search space, which has to be either a Json primitive type or a nested search space.
diff --git a/eng/Versions.props b/eng/Versions.props
index cd8263f553..3997aaf8fa 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -86,7 +86,6 @@
0.13.12
6.0.36
8.0.16
- 8.1.0
1.1.2
9.0.0-beta.24212.4
5.0.0-preview.5.20278.1
diff --git a/src/Microsoft.ML.SearchSpace/Readme.md b/src/Microsoft.ML.SearchSpace/Readme.md
index ec9a07241b..fbfa29d0d9 100644
--- a/src/Microsoft.ML.SearchSpace/Readme.md
+++ b/src/Microsoft.ML.SearchSpace/Readme.md
@@ -25,6 +25,8 @@ Provides some basic tuning algoritions (GridSearch, etc..)
## Examples
``` csharp
+using Xunit;
+
private class BasicSearchSpace
{
[Range(-1000, 1000, init: 0)]
@@ -55,17 +57,17 @@ var tuner = new DefaultValueTuner(ss);
// Get one sampling result from tuner
BasicSearchSpace param = tuner.Propose();
-// param.UniformInt.Should().Be(0);
-// param.ChoiceStr.Should().Be("a"); // no default value designate for ChoiceStr, so the first value will be used.
-// param.NestSS.UniformInt.Should().Be(0);
+// Assert.Equal(0, param.UniformInt);
+// Assert.Equal("a", param.ChoiceStr); // no default value designate for ChoiceStr, so the first value will be used.
+// Assert.Equal(0, param.NestSS.UniformInt);
// Or you can also sample from scratch
// The feature of ss is a 4-d [0, 1) vector.
BasicSearchSpace param2 = ss.SampleFromFeatureSpace(new[] {0.5, 0, 0.5, 0});
-// (param == param2).Should().BeTrue();
+// Assert.True(param == param2);
// You can also map param back to feature space
-ss.MappingToFeatureSpace(param).Should().BeEquivalentTo(0.5, 0, 0.5, 0);
+Assert.Equivalent(new[] { 0.5, 0, 0.5, 0 }, ss.MappingToFeatureSpace(param), strict: true);
```
diff --git a/test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs b/test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs
index 04df47c3bf..a2af752f43 100644
--- a/test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/AutoFitTests.cs
@@ -7,7 +7,6 @@
using System.Globalization;
using System.Linq;
using System.Threading;
-using FluentAssertions;
using Microsoft.ML.Data;
using Microsoft.ML.Runtime;
using Microsoft.ML.TestFramework;
@@ -85,7 +84,7 @@ public void AutoFit_UCI_Adult_AutoZero_Test()
var result = context.Auto()
.CreateBinaryClassificationExperiment(settings)
.Execute(trainData, new ColumnInformation() { LabelColumnName = DatasetUtil.UciAdultLabel });
- result.BestRun.ValidationMetrics.Accuracy.Should().BeGreaterThanOrEqualTo(0.7);
+ Assert.True(result.BestRun.ValidationMetrics.Accuracy >= 0.7);
Assert.NotNull(result.BestRun.Estimator);
Assert.NotNull(result.BestRun.Model);
Assert.NotNull(result.BestRun.TrainerName);
@@ -285,7 +284,7 @@ public void AutoFitMultiTest(bool useNumberOfCVFolds)
.CreateMulticlassClassificationExperiment(settings)
.Execute(trainData, numberOfCVFolds, DatasetUtil.TrivialMulticlassDatasetLabel);
- result.BestRun.Results.First().ValidationMetrics.MicroAccuracy.Should().BeGreaterThan(0.7);
+ Assert.True(result.BestRun.Results.First().ValidationMetrics.MicroAccuracy > 0.7);
var scoredData = result.BestRun.Results.First().Model.Transform(trainData);
Assert.Equal(NumberDataViewType.Single, scoredData.Schema[DefaultColumnNames.PredictedLabel].Type);
@@ -347,7 +346,7 @@ public void AutoFitMultiClassification_Image_TrainTest()
.CreateMulticlassClassificationExperiment(settings)
.Execute(trainDataset, testDataset, columnInference.ColumnInformation);
- result.BestRun.ValidationMetrics.MicroAccuracy.Should().BeGreaterThan(0.1);
+ Assert.True(result.BestRun.ValidationMetrics.MicroAccuracy > 0.1);
var scoredData = result.BestRun.Model.Transform(trainData);
Assert.Equal(TextDataViewType.Instance, scoredData.Schema[DefaultColumnNames.PredictedLabel].Type);
@@ -370,7 +369,7 @@ public void AutoFitMultiClassification_Image_CV()
.CreateMulticlassClassificationExperiment(settings)
.Execute(trainData, 5, columnInference.ColumnInformation);
- result.BestRun.Results.Select(x => x.ValidationMetrics.MicroAccuracy).Max().Should().BeGreaterThan(0.1);
+ Assert.True(result.BestRun.Results.Select(x => x.ValidationMetrics.MicroAccuracy).Max() > 0.1);
var scoredData = result.BestRun.Results.First().Model.Transform(trainData);
Assert.Equal(TextDataViewType.Instance, scoredData.Schema[DefaultColumnNames.PredictedLabel].Type);
diff --git a/test/Microsoft.ML.AutoML.Tests/AutoMLExperimentTests.cs b/test/Microsoft.ML.AutoML.Tests/AutoMLExperimentTests.cs
index 013d05e1c3..b64070e468 100644
--- a/test/Microsoft.ML.AutoML.Tests/AutoMLExperimentTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/AutoMLExperimentTests.cs
@@ -10,7 +10,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.Data.Analysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.ML.AutoML.CodeGen;
@@ -54,9 +53,7 @@ public async Task AutoMLExperiment_throw_timeout_exception_when_ct_is_canceled_a
}
};
- var runExperimentAction = async () => await experiment.RunAsync(cts.Token);
-
- await runExperimentAction.Should().ThrowExactlyAsync();
+ await Assert.ThrowsAsync(() => experiment.RunAsync(cts.Token));
}
[Fact]
@@ -84,8 +81,7 @@ public async Task AutoMLExperiment_cancel_trial_when_exceeds_memory_limit_Async(
.SetTuner()
.SetMaximumMemoryUsageInMegaByte(0.01);
- var runExperimentAction = async () => await experiment.RunAsync();
- await runExperimentAction.Should().ThrowExactlyAsync();
+ await Assert.ThrowsAsync(() => experiment.RunAsync());
}
[LightGBMFact]
@@ -111,8 +107,7 @@ public async Task AutoMLExperiment_lgbm_cancel_trial_when_exceeds_memory_limit_A
.SetTrainingTimeInSeconds(10)
.SetMaximumMemoryUsageInMegaByte(10);
- var runExperimentAction = async () => await experiment.RunAsync();
- await runExperimentAction.Should().ThrowExactlyAsync();
+ await Assert.ThrowsAsync(() => experiment.RunAsync());
}
[Fact]
@@ -143,9 +138,9 @@ public async Task AutoMLExperiment_return_current_best_trial_when_ct_is_canceled
var res = await experiment.RunAsync(cts.Token);
stopWatch.Stop();
- stopWatch.ElapsedMilliseconds.Should().BeLessThanOrEqualTo(5000);
- cts.IsCancellationRequested.Should().BeTrue();
- res.Metric.Should().BeGreaterThan(0);
+ Assert.True(stopWatch.ElapsedMilliseconds <= 5000);
+ Assert.True(cts.IsCancellationRequested);
+ Assert.True(res.Metric > 0);
}
[Fact]
@@ -174,8 +169,8 @@ public async Task AutoMLExperiment_finish_training_when_time_is_up_Async()
cts.CancelAfter(100 * 1000);
var res = await experiment.RunAsync(cts.Token);
- res.Metric.Should().BeGreaterThan(0);
- cts.IsCancellationRequested.Should().BeFalse();
+ Assert.True(res.Metric > 0);
+ Assert.False(cts.IsCancellationRequested);
cts.Dispose();
}
@@ -202,7 +197,7 @@ public async Task AutoMLExperiment_finish_training_when_reach_to_max_model_async
}
};
await experiment.RunAsync();
- runModelCounts.Should().Be(5);
+ Assert.Equal(5, runModelCounts);
}
@@ -228,7 +223,7 @@ public async Task AutoMLExperiment_UCI_Adult_Train_Test_Split_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.8);
+ Assert.True(result.Metric > 0.8);
}
[Fact(Skip = "skip in CI build")]
@@ -253,7 +248,7 @@ public async Task AutoMLExperiment_UCI_Adult_Fairlearn_Test()
.SetMaxModelToExplore(100);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.8);
+ Assert.True(result.Metric > 0.8);
}
[Fact]
@@ -278,7 +273,7 @@ public async Task AutoMLExperiment_UCI_Adult_CV_5_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.8);
+ Assert.True(result.Metric > 0.8);
}
[Fact]
@@ -305,7 +300,7 @@ public async Task AutoMLExperiment_Iris_CV_5_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.8);
+ Assert.True(result.Metric > 0.8);
}
[Fact]
@@ -332,7 +327,7 @@ public async Task AutoMLExperiment_Iris_Train_Test_Split_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.8);
+ Assert.True(result.Metric > 0.8);
}
[Fact]
@@ -359,7 +354,7 @@ public async Task AutoMLExperiment_Taxi_Fare_Train_Test_Split_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.5);
+ Assert.True(result.Metric > 0.5);
// test subsamping
experiment = context.Auto().CreateExperiment();
@@ -368,9 +363,9 @@ public async Task AutoMLExperiment_Taxi_Fare_Train_Test_Split_Test()
.SetPipeline(pipeline)
.SetMaxModelToExplore(1);
result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.5);
- result.TrialSettings.Parameter[nameof(TrainValidateDatasetManager)]["TrainValidateDatasetSubsamplingKey"]
- .AsType().Should().Be(0.1f);
+ Assert.True(result.Metric > 0.5);
+ Assert.Equal(0.1f, result.TrialSettings.Parameter[nameof(TrainValidateDatasetManager)]["TrainValidateDatasetSubsamplingKey"]
+ .AsType());
}
[Fact]
@@ -389,7 +384,7 @@ public async Task AutoMLExperiment_Taxi_Fare_CV_5_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.5);
+ Assert.True(result.Metric > 0.5);
}
[Fact]
@@ -408,8 +403,8 @@ public async Task AutoMLExperiment_Taxi_Fare_CV_5_SamplingKey_Test()
.SetMaxModelToExplore(1);
var result = await experiment.RunAsync();
- result.Metric.Should().BeGreaterThan(0.2);
- result.Metric.Should().BeLessThan(0.5);
+ Assert.True(result.Metric > 0.2);
+ Assert.True(result.Metric < 0.5);
}
[Fact]
@@ -418,12 +413,12 @@ public void AutoMLExperiment_should_use_seed_from_context_if_provided()
var context = new MLContext();
var experiment = context.Auto().CreateExperiment();
var settings = experiment.ServiceCollection.BuildServiceProvider().GetRequiredService();
- settings.Seed.Should().BeNull();
+ Assert.Null(settings.Seed);
context = new MLContext(1);
experiment = context.Auto().CreateExperiment();
settings = experiment.ServiceCollection.BuildServiceProvider().GetRequiredService();
- settings.Seed.Should().Be(1);
+ Assert.Equal(1, settings.Seed);
}
}
diff --git a/test/Microsoft.ML.AutoML.Tests/ColumnInferenceTests.cs b/test/Microsoft.ML.AutoML.Tests/ColumnInferenceTests.cs
index 09d0aaffd7..5a85638fea 100644
--- a/test/Microsoft.ML.AutoML.Tests/ColumnInferenceTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/ColumnInferenceTests.cs
@@ -9,7 +9,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.Data;
using Microsoft.ML.TestFramework;
using Newtonsoft.Json;
@@ -205,9 +204,9 @@ public void TrySplitColumns_should_split_on_dataset_with_newline_between_double_
var sample = TextFileSample.CreateFromFullFile(dataset);
var result = TextFileContents.TrySplitColumns(context, sample, TextFileContents.DefaultSeparators);
- result.ColumnCount.Should().Be(4);
- result.Separator.Should().Be(',');
- result.IsSuccess.Should().BeTrue();
+ Assert.Equal(4, result.ColumnCount);
+ Assert.Equal(',', result.Separator);
+ Assert.True(result.IsSuccess);
}
[Fact]
diff --git a/test/Microsoft.ML.AutoML.Tests/EntityTest.cs b/test/Microsoft.ML.AutoML.Tests/EntityTest.cs
index e6d598151c..453600b472 100644
--- a/test/Microsoft.ML.AutoML.Tests/EntityTest.cs
+++ b/test/Microsoft.ML.AutoML.Tests/EntityTest.cs
@@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using FluentAssertions;
using Microsoft.ML.TestFramework;
using Xunit;
using Xunit.Abstractions;
@@ -27,10 +26,10 @@ public void Entity_operator_overload_test()
var b = new StringEntity("b");
var c = new StringEntity("c");
- (a + b + c).ToString().Should().Be("a + b + c");
- (a * b * c).ToString().Should().Be("a * b * c");
- (a + b * c).ToString().Should().Be("a + b * c");
- ((a + b) * c).ToString().Should().Be("(a + b) * c");
+ Assert.Equal("a + b + c", (a + b + c).ToString());
+ Assert.Equal("a * b * c", (a * b * c).ToString());
+ Assert.Equal("a + b * c", (a + b * c).ToString());
+ Assert.Equal("(a + b) * c", ((a + b) * c).ToString());
}
[Fact]
@@ -42,16 +41,16 @@ public void Entity_symplify_test()
var d = new StringEntity("d");
var e = new StringEntity("e");
- (a + b + c + d + e).Simplify().ToString().Should().Be("a + b + c + d + e");
- ((a + b) + (c + d) + e).Simplify().ToString().Should().Be("a + b + c + d + e");
- (a * b * c * d * e).Simplify().ToString().Should().Be("a * b * c * d * e");
- ((a * b) * c * (d * e)).Simplify().ToString().Should().Be("a * b * c * d * e");
- (a * (b + c + d * e)).Simplify().ToString().Should().Be("a * b + a * c + a * d * e");
- (a * (b + c * d)).Simplify().ToString().Should().Be("a * b + a * c * d");
- ((a + b) * (c + d)).Simplify().ToString().Should().Be("a * c + a * d + b * c + b * d");
- (a * (b + c) * (d + e)).Simplify().ToString().Should().Be("a * b * d + a * b * e + a * c * d + a * c * e");
- ((a + b + c + d * e) * e).Simplify().ToString().Should().Be("a * e + b * e + c * e + d * e * e");
- ((a + b + c) * (b + c + d) * (d + e)).Simplify().ToString().Should().Be("a * b * d + a * c * d + b * b * d + b * c * d + a * d * d + b * d * d + c * b * d + c * c * d + a * b * e + a * c * e + b * b * e + b * c * e + a * d * e + b * d * e + c * b * e + c * c * e + c * d * d + c * d * e");
+ Assert.Equal("a + b + c + d + e", (a + b + c + d + e).Simplify().ToString());
+ Assert.Equal("a + b + c + d + e", ((a + b) + (c + d) + e).Simplify().ToString());
+ Assert.Equal("a * b * c * d * e", (a * b * c * d * e).Simplify().ToString());
+ Assert.Equal("a * b * c * d * e", ((a * b) * c * (d * e)).Simplify().ToString());
+ Assert.Equal("a * b + a * c + a * d * e", (a * (b + c + d * e)).Simplify().ToString());
+ Assert.Equal("a * b + a * c * d", (a * (b + c * d)).Simplify().ToString());
+ Assert.Equal("a * c + a * d + b * c + b * d", ((a + b) * (c + d)).Simplify().ToString());
+ Assert.Equal("a * b * d + a * b * e + a * c * d + a * c * e", (a * (b + c) * (d + e)).Simplify().ToString());
+ Assert.Equal("a * e + b * e + c * e + d * e * e", ((a + b + c + d * e) * e).Simplify().ToString());
+ Assert.Equal("a * b * d + a * c * d + b * b * d + b * c * d + a * d * d + b * d * d + c * b * d + c * c * d + a * b * e + a * c * e + b * b * e + b * c * e + a * d * e + b * d * e + c * b * e + c * c * e + c * d * d + c * d * e", ((a + b + c) * (b + c + d) * (d + e)).Simplify().ToString());
}
[Fact]
@@ -62,23 +61,11 @@ public void Entity_to_terms_test()
var c = new StringEntity("c");
var d = new StringEntity("d");
var e = new StringEntity("e");
- a.ToTerms()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a");
- (a * b * c * d * e).ToTerms()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a * b * c * d * e");
- (a + b + c + d + e).ToTerms()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a", "b", "c", "d", "e");
+ Assert.Equivalent(new[] { "a" }, a.ToTerms().Select(x => x.ToString()), strict: true);
+ Assert.Equivalent(new[] { "a * b * c * d * e" }, (a * b * c * d * e).ToTerms().Select(x => x.ToString()), strict: true);
+ Assert.Equivalent(new[] { "a", "b", "c", "d", "e" }, (a + b + c + d + e).ToTerms().Select(x => x.ToString()), strict: true);
- (a + b + c + d * e).ToTerms()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a", "b", "c", "d * e");
+ Assert.Equivalent(new[] { "a", "b", "c", "d * e" }, (a + b + c + d * e).ToTerms().Select(x => x.ToString()), strict: true);
}
[Fact]
@@ -89,36 +76,24 @@ public void Entity_to_value_test()
var c = new StringEntity("c");
var d = new StringEntity("d");
var e = new StringEntity("e");
- a.ValueEntities()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a");
- (a * b * c * d * e).ValueEntities()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a", "b", "c", "d", "e");
- (a + b + c + d + e).ValueEntities()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a", "b", "c", "d", "e");
+ Assert.Equivalent(new[] { "a" }, a.ValueEntities().Select(x => x.ToString()), strict: true);
+ Assert.Equivalent(new[] { "a", "b", "c", "d", "e" }, (a * b * c * d * e).ValueEntities().Select(x => x.ToString()), strict: true);
+ Assert.Equivalent(new[] { "a", "b", "c", "d", "e" }, (a + b + c + d + e).ValueEntities().Select(x => x.ToString()), strict: true);
- (a + b + c + d * e).ValueEntities()
- .Select(x => x.ToString())
- .Should()
- .BeEquivalentTo("a", "b", "c", "d", "e");
+ Assert.Equivalent(new[] { "a", "b", "c", "d", "e" }, (a + b + c + d * e).ValueEntities().Select(x => x.ToString()), strict: true);
}
[Fact]
public void Entity_create_from_expression()
{
var entity = Entity.FromExpression("a+b+c");
- entity.ToString().Should().Be("a + b + c");
+ Assert.Equal("a + b + c", entity.ToString());
entity = Entity.FromExpression("abc");
- entity.ToString().Should().Be("abc");
+ Assert.Equal("abc", entity.ToString());
entity = Entity.FromExpression("(a+b)*(c+d)");
- entity.ToString().Should().Be("(a + b) * (c + d)");
+ Assert.Equal("(a + b) * (c + d)", entity.ToString());
}
}
}
diff --git a/test/Microsoft.ML.AutoML.Tests/GridSearchTunerTests.cs b/test/Microsoft.ML.AutoML.Tests/GridSearchTunerTests.cs
index fab4f0de67..411a630efc 100644
--- a/test/Microsoft.ML.AutoML.Tests/GridSearchTunerTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/GridSearchTunerTests.cs
@@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using FluentAssertions;
using Microsoft.ML.SearchSpace;
using Microsoft.ML.TestFramework;
using Xunit;
@@ -51,8 +50,8 @@ public void GridSearchTuner_should_search_entire_naive_search_space()
parameters.Add(tuner.Propose(settings));
}
- steps.Should().Be(600);
- parameters.Distinct().Count().Should().Be(steps);
+ Assert.Equal(600, steps);
+ Assert.Equal(steps, parameters.Distinct().Count());
}
private class NaiveSearchSpace
diff --git a/test/Microsoft.ML.AutoML.Tests/MLContextManagerTests.cs b/test/Microsoft.ML.AutoML.Tests/MLContextManagerTests.cs
index ef44c45e94..6306420c7a 100644
--- a/test/Microsoft.ML.AutoML.Tests/MLContextManagerTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/MLContextManagerTests.cs
@@ -7,7 +7,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.ML.Data;
using Microsoft.ML.Runtime;
using Microsoft.ML.TestFramework;
@@ -33,11 +32,11 @@ public void DefaultMLContextManager_should_create_child_context_base_on_main_con
var contextManager = new DefaultMLContextManager(mainContext);
var childContext = contextManager.CreateMLContext();
- childContext.GpuDeviceId.Should().Be(10);
- childContext.FallbackToCpu.Should().BeFalse();
- childContext.TempFilePath.Should().Be("temp");
+ Assert.Equal(10, childContext.GpuDeviceId);
+ Assert.False(childContext.FallbackToCpu);
+ Assert.Equal("temp", childContext.TempFilePath);
- ((IHostEnvironmentInternal)childContext.Model.GetEnvironment()).Seed.Should().Be(10);
+ Assert.Equal(10, ((IHostEnvironmentInternal)childContext.Model.GetEnvironment()).Seed);
}
[Fact]
@@ -60,7 +59,7 @@ public void DefaultMLContextManager_main_context_should_replay_log_from_child_co
channel.Info("info");
channel.Error("error");
- messages.Count().Should().Be(4);
+ Assert.Equal(4, messages.Count());
}
}
}
diff --git a/test/Microsoft.ML.AutoML.Tests/Microsoft.ML.AutoML.Tests.csproj b/test/Microsoft.ML.AutoML.Tests/Microsoft.ML.AutoML.Tests.csproj
index cc7bf33b65..c16b7a6b41 100644
--- a/test/Microsoft.ML.AutoML.Tests/Microsoft.ML.AutoML.Tests.csproj
+++ b/test/Microsoft.ML.AutoML.Tests/Microsoft.ML.AutoML.Tests.csproj
@@ -23,7 +23,6 @@
-
diff --git a/test/Microsoft.ML.AutoML.Tests/StopTrainingManagerTests.cs b/test/Microsoft.ML.AutoML.Tests/StopTrainingManagerTests.cs
index 4e87bf238d..a5c4fc5055 100644
--- a/test/Microsoft.ML.AutoML.Tests/StopTrainingManagerTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/StopTrainingManagerTests.cs
@@ -8,7 +8,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.ML.TestFramework;
using Xunit;
using Xunit.Abstractions;
@@ -34,12 +33,12 @@ public void CancellationTokenStopTrainingManager_isStopTrainingRequested_test()
isOnStopTrainingGetInvoked = true;
};
- manager.IsStopTrainingRequested().Should().BeFalse();
+ Assert.False(manager.IsStopTrainingRequested());
cts.Cancel();
- manager.IsStopTrainingRequested().Should().BeTrue();
- isOnStopTrainingGetInvoked.Should().BeTrue();
+ Assert.True(manager.IsStopTrainingRequested());
+ Assert.True(isOnStopTrainingGetInvoked);
}
[Fact]
@@ -62,8 +61,8 @@ public async Task TimeoutTrainingStopManager_isStopTrainingRequested_test()
});
await waitForCompleted;
- manager.IsStopTrainingRequested().Should().BeTrue();
- isOnStopTrainingGetInvoked.Should().BeTrue();
+ Assert.True(manager.IsStopTrainingRequested());
+ Assert.True(isOnStopTrainingGetInvoked);
}
[Fact]
@@ -89,10 +88,10 @@ public async Task AggregateTrainingStopManager_isStopTrainingRequested_test()
});
await waitForCompleted;
- aggregationManager.IsStopTrainingRequested().Should().BeTrue();
- timeoutManager.IsStopTrainingRequested().Should().BeTrue();
- cancellationManager.IsStopTrainingRequested().Should().BeFalse();
- isOnStopTrainingGetInvoked.Should().BeTrue();
+ Assert.True(aggregationManager.IsStopTrainingRequested());
+ Assert.True(timeoutManager.IsStopTrainingRequested());
+ Assert.False(cancellationManager.IsStopTrainingRequested());
+ Assert.True(isOnStopTrainingGetInvoked);
aggregationManager = new AggregateTrainingStopManager(null, new TimeoutTrainingStopManager(TimeSpan.FromSeconds(100), null), cancellationManager);
isOnStopTrainingGetInvoked = false;
@@ -103,9 +102,9 @@ public async Task AggregateTrainingStopManager_isStopTrainingRequested_test()
cts.Cancel();
await waitForCompleted;
- aggregationManager.IsStopTrainingRequested().Should().BeTrue();
- cancellationManager.IsStopTrainingRequested().Should().BeTrue();
- isOnStopTrainingGetInvoked.Should().BeTrue();
+ Assert.True(aggregationManager.IsStopTrainingRequested());
+ Assert.True(cancellationManager.IsStopTrainingRequested());
+ Assert.True(isOnStopTrainingGetInvoked);
}
}
}
diff --git a/test/Microsoft.ML.AutoML.Tests/SweepableEstimatorPipelineTest.cs b/test/Microsoft.ML.AutoML.Tests/SweepableEstimatorPipelineTest.cs
index 5837b69966..a5edd080aa 100644
--- a/test/Microsoft.ML.AutoML.Tests/SweepableEstimatorPipelineTest.cs
+++ b/test/Microsoft.ML.AutoML.Tests/SweepableEstimatorPipelineTest.cs
@@ -11,7 +11,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.AutoML.CodeGen;
using Microsoft.ML.TestFramework;
using Xunit;
@@ -49,8 +48,8 @@ public void SweepableEstimatorPipeline_append_test()
var pipeline = new SweepableEstimatorPipeline();
pipeline = pipeline.Append(e1).Append(e2);
- pipeline.ToString().Should().Be("Concatenate=>ConvertType");
- pipeline.SearchSpace.FeatureSpaceDim.Should().Be(0);
+ Assert.Equal("Concatenate=>ConvertType", pipeline.ToString());
+ Assert.Equal(0, pipeline.SearchSpace.FeatureSpaceDim);
}
[Fact]
@@ -64,9 +63,9 @@ public void MultiModelPipeline_append_test()
var pipeline = new MultiModelPipeline();
pipeline = pipeline.Append(e1, e2).AppendOrSkip(e3, e4);
- pipeline.Schema.ToString().Should().Be("(e0 + e1) * (e2 + e3 + Nil)");
- pipeline.BuildSweepableEstimatorPipeline("e0 * e2").ToString().Should().Be("Concatenate=>ApplyOnnxModel");
- pipeline.BuildSweepableEstimatorPipeline("e1 * Nil").ToString().Should().Be("ConvertType");
+ Assert.Equal("(e0 + e1) * (e2 + e3 + Nil)", pipeline.Schema.ToString());
+ Assert.Equal("Concatenate=>ApplyOnnxModel", pipeline.BuildSweepableEstimatorPipeline("e0 * e2").ToString());
+ Assert.Equal("ConvertType", pipeline.BuildSweepableEstimatorPipeline("e1 * Nil").ToString());
}
[Fact]
@@ -86,14 +85,14 @@ public void MultiModelPipeline_append_pipeline_test()
pipeline1 = pipeline1.Append(pipeline2);
- pipeline1.Schema.ToString().Should().Be("(e0 + e1 * e2) * (e3 * (e4 + e5) + e6)");
+ Assert.Equal("(e0 + e1 * e2) * (e3 * (e4 + e5) + e6)", pipeline1.Schema.ToString());
}
[Fact]
public void SweepableEstimatorPipeline_search_space_test()
{
var pipeline = CreateSweepbaleEstimatorPipeline();
- pipeline.SearchSpace.FeatureSpaceDim.Should().Be(15);
+ Assert.Equal(15, pipeline.SearchSpace.FeatureSpaceDim);
// TODO
// verify other properties in search space.
@@ -105,11 +104,11 @@ public void SweepableEstimatorPipeline_can_be_created_from_MultiModelPipeline()
var multiModelPipeline = CreateMultiModelPipeline();
var pipelines = multiModelPipeline.PipelineIds;
- pipelines.Should().BeEquivalentTo("e0 * e3 * e4", "e1 * e2 * e3 * e4", "e0 * Nil * e4", "e1 * e2 * Nil * e4", "Nil * e3 * e4", "e0 * e3 * e5", "e1 * e2 * e3 * e5", "e0 * Nil * e5", "e1 * e2 * Nil * e5", "Nil * e3 * e5", "Nil * Nil * e4", "Nil * Nil * e5");
+ Assert.Equivalent(new[] { "e0 * e3 * e4", "e1 * e2 * e3 * e4", "e0 * Nil * e4", "e1 * e2 * Nil * e4", "Nil * e3 * e4", "e0 * e3 * e5", "e1 * e2 * e3 * e5", "e0 * Nil * e5", "e1 * e2 * Nil * e5", "Nil * e3 * e5", "Nil * Nil * e4", "Nil * Nil * e5" }, pipelines, strict: true);
var singleModelPipeline = multiModelPipeline.BuildSweepableEstimatorPipeline(pipelines[0]);
- singleModelPipeline.ToString().Should().Be("ReplaceMissingValues=>Concatenate=>LightGbmBinary");
+ Assert.Equal("ReplaceMissingValues=>Concatenate=>LightGbmBinary", singleModelPipeline.ToString());
singleModelPipeline = multiModelPipeline.BuildSweepableEstimatorPipeline(pipelines[2]);
- singleModelPipeline.ToString().Should().Be("ReplaceMissingValues=>LightGbmBinary");
+ Assert.Equal("ReplaceMissingValues=>LightGbmBinary", singleModelPipeline.ToString());
}
[Fact]
diff --git a/test/Microsoft.ML.AutoML.Tests/SweepableExtensionTest.cs b/test/Microsoft.ML.AutoML.Tests/SweepableExtensionTest.cs
index 0afa1a1ea7..4dd85ae8f1 100644
--- a/test/Microsoft.ML.AutoML.Tests/SweepableExtensionTest.cs
+++ b/test/Microsoft.ML.AutoML.Tests/SweepableExtensionTest.cs
@@ -11,7 +11,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.AutoML.CodeGen;
using Microsoft.ML.TestFramework;
using Xunit;
@@ -50,7 +49,7 @@ public void CreateSweepablePipelineFromIEstimatorTest()
var estimator = context.Transforms.Concatenate("output", "input");
var pipeline = estimator.Append(SweepableEstimatorFactory.CreateFastForestBinary(new FastForestOption()));
- pipeline.Should().BeOfType();
+ Assert.IsType(pipeline);
}
[Fact]
@@ -59,7 +58,7 @@ public void CreateSweepablePipelineFromSweepableEstimatorTest()
var estimator = SweepableEstimatorFactory.CreateFastForestBinary(new FastForestOption());
var pipeline = estimator.Append(estimator);
- pipeline.Should().BeOfType();
+ Assert.IsType(pipeline);
}
[Fact]
@@ -69,7 +68,7 @@ public void CreateSweepablePipelineFromSweepableEstimatorAndIEstimatorTest()
var estimator = SweepableEstimatorFactory.CreateFastForestBinary(new FastForestOption());
var pipeline = estimator.Append(context.Transforms.Concatenate("output", "input"));
- pipeline.Should().BeOfType();
+ Assert.IsType(pipeline);
}
[Fact]
@@ -188,7 +187,7 @@ public void AppendIEstimatorToSweepabePipelineTest()
var pipeline = estimator.Append(SweepableEstimatorFactory.CreateFastForestBinary(new FastForestOption()), SweepableEstimatorFactory.CreateFastForestBinary(new FastForestOption()));
pipeline = pipeline.Append(context.Transforms.CopyColumns("output", "input"));
- pipeline.Should().BeOfType();
+ Assert.IsType(pipeline);
var json = JsonSerializer.Serialize(pipeline, _jsonSerializerOptions);
Approvals.Verify(json);
}
diff --git a/test/Microsoft.ML.AutoML.Tests/TrainValidaionDatasetManagerTest.cs b/test/Microsoft.ML.AutoML.Tests/TrainValidaionDatasetManagerTest.cs
index aa03befceb..d870c80a61 100644
--- a/test/Microsoft.ML.AutoML.Tests/TrainValidaionDatasetManagerTest.cs
+++ b/test/Microsoft.ML.AutoML.Tests/TrainValidaionDatasetManagerTest.cs
@@ -7,7 +7,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.ML.AutoML.Test;
using Microsoft.ML.SearchSpace;
using Microsoft.ML.TestFramework;
@@ -32,7 +31,7 @@ public void TrainValidationDatasetManagerSubSamplingTest()
var trainData = textLoader.Load(dataPath);
var trainDataLength = DatasetDimensionsUtil.CountRows(trainData, ulong.MaxValue);
- trainDataLength.Should().Be(500);
+ Assert.Equal(500UL, trainDataLength);
var trainValidationDatasetManager = new TrainValidateDatasetManager(trainData, trainData, "SubSampleKey");
@@ -46,7 +45,7 @@ public void TrainValidationDatasetManagerSubSamplingTest()
var subSampleTrainData = trainValidationDatasetManager.LoadTrainDataset(context, setting);
var subSampleTrainDataLength = DatasetDimensionsUtil.CountRows(subSampleTrainData, ulong.MaxValue);
- subSampleTrainDataLength.Should().Be(150);
+ Assert.Equal(150UL, subSampleTrainDataLength);
}
}
}
diff --git a/test/Microsoft.ML.AutoML.Tests/TrialResultManagerTest.cs b/test/Microsoft.ML.AutoML.Tests/TrialResultManagerTest.cs
index 74345c2ba8..1f20bdd22f 100644
--- a/test/Microsoft.ML.AutoML.Tests/TrialResultManagerTest.cs
+++ b/test/Microsoft.ML.AutoML.Tests/TrialResultManagerTest.cs
@@ -10,7 +10,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.AutoML.CodeGen;
using Microsoft.ML.TestFramework;
using Xunit;
@@ -54,28 +53,28 @@ public void CsvTrialResultManager_end_to_end_test()
var csvTrialResultManager = new CsvTrialResultManager(tempFilePath, lgbmSearchSpace);
// the tempFile is empty, so GetAllTrialResults should be 0;
- csvTrialResultManager.GetAllTrialResults().Count().Should().Be(0);
+ Assert.Empty(csvTrialResultManager.GetAllTrialResults());
// Add trialResults to csvTrialResultManager, the # of trials should be 10.
foreach (var trialResult in trialResults)
{
csvTrialResultManager.AddOrUpdateTrialResult(trialResult);
}
- csvTrialResultManager.GetAllTrialResults().Count().Should().Be(10);
+ Assert.Equal(10, csvTrialResultManager.GetAllTrialResults().Count());
// if repeated trial added, csvTrialResultManager should update the existing trial.
foreach (var trialResult in trialResults)
{
csvTrialResultManager.AddOrUpdateTrialResult(trialResult);
}
- csvTrialResultManager.GetAllTrialResults().Count().Should().Be(10);
+ Assert.Equal(10, csvTrialResultManager.GetAllTrialResults().Count());
// save as csv test
csvTrialResultManager.Save();
// reload test.
csvTrialResultManager = new CsvTrialResultManager(tempFilePath, lgbmSearchSpace);
- csvTrialResultManager.GetAllTrialResults().Count().Should().Be(10);
+ Assert.Equal(10, csvTrialResultManager.GetAllTrialResults().Count());
var fileContent = File.ReadAllText(tempFilePath);
diff --git a/test/Microsoft.ML.AutoML.Tests/TunerTests.cs b/test/Microsoft.ML.AutoML.Tests/TunerTests.cs
index 747667f40b..2176e04c1e 100644
--- a/test/Microsoft.ML.AutoML.Tests/TunerTests.cs
+++ b/test/Microsoft.ML.AutoML.Tests/TunerTests.cs
@@ -8,7 +8,6 @@
using System.Linq;
using System.Text;
using System.Threading;
-using FluentAssertions;
using Microsoft.ML.AutoML.CodeGen;
using Microsoft.ML.SearchSpace;
using Microsoft.ML.SearchSpace.Tuner;
@@ -53,8 +52,8 @@ public void tuner_e2e_test()
trialSettings.Parameter = param;
var option = param.AsType();
- option.L1Regularization.Should().BeInRange(0.03125f, 32768.0f);
- option.L2Regularization.Should().BeInRange(0.03125f, 32768.0f);
+ Assert.InRange(option.L1Regularization, 0.03125f, 32768.0f);
+ Assert.InRange(option.L2Regularization, 0.03125f, 32768.0f);
tuner.Update(new TrialResult()
{
@@ -84,8 +83,8 @@ public void Smac_should_ignore_fail_trials_during_initialize()
trialSettings.Parameter = param;
var option = param.AsType();
- option.L1Regularization.Should().BeInRange(0.03125f, 32768.0f);
- option.L2Regularization.Should().BeInRange(0.03125f, 32768.0f);
+ Assert.InRange(option.L1Regularization, 0.03125f, 32768.0f);
+ Assert.InRange(option.L2Regularization, 0.03125f, 32768.0f);
tuner.Update(new TrialResult()
{
@@ -95,8 +94,8 @@ public void Smac_should_ignore_fail_trials_during_initialize()
});
}
- tuner.Candidates.Count.Should().Be(0);
- tuner.Histories.Count.Should().Be(0);
+ Assert.Empty(tuner.Candidates);
+ Assert.Empty(tuner.Histories);
}
[Fact]
@@ -138,8 +137,8 @@ public void CFO_should_be_recoverd_if_history_provided()
var nextParameterFromNewCfo = newCfo.Propose(trialSettings);
var lseParameterFromNewCfo = nextParameterFromNewCfo.AsType();
var lossFromNewCfo = -LSE3D(lseParameterFromNewCfo.X, lseParameterFromNewCfo.Y, lseParameterFromNewCfo.Z);
- lastResult.Loss.Should().BeApproximately(-10.1537, 1e-3);
- lossFromNewCfo.Should().BeApproximately(-11.0986, 0.01);
+ Assert.Equal(-10.1537, lastResult.Loss, tolerance: 1e-3);
+ Assert.Equal(-11.0986, lossFromNewCfo, tolerance: 0.01);
}
[Fact]
@@ -157,7 +156,7 @@ public void CFO_should_start_from_init_point_if_provided()
var y = param.Y;
var z = param.Z;
- (x * x + y * y + z * z).Should().Be(0);
+ Assert.Equal(0.0, x * x + y * y + z * z);
}
[Fact]
@@ -280,7 +279,7 @@ public void LSE_maximize_test()
// 10.5 is the best metric from random tuner
// and the other tuners should achieve better metric comparing with random tuner.
- bestMetric.Should().BeGreaterThanOrEqualTo(10.5);
+ Assert.True(bestMetric >= 10.5);
}
}
@@ -331,7 +330,7 @@ public void LSE_minimize_test()
}
Output.WriteLine($"best metric: {bestLoss}");
- bestLoss.Should().BeLessThan(-7);
+ Assert.True(bestLoss < -7);
}
}
@@ -380,7 +379,7 @@ public void F1_minimize_test()
// 6.1 is the best metric from random tuner.
// and we assume that other tuners should achieve better result than random tuner
- bestMetric.Should().BeLessThan(6.1);
+ Assert.True(bestMetric < 6.1);
}
}
@@ -394,7 +393,7 @@ public void Hyper_parameters_from_CFO_should_be_culture_invariant_string()
var usCulture = new CultureInfo("en-US", false);
Thread.CurrentThread.CurrentCulture = usCulture;
- Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator.Should().Be(".");
+ Assert.Equal(".", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
for (int i = 0; i != 100; ++i)
{
var trialSettings = new TrialSettings()
@@ -402,12 +401,12 @@ public void Hyper_parameters_from_CFO_should_be_culture_invariant_string()
TrialId = i,
};
var param = cfo.Propose(trialSettings).AsType();
- param.X.Should().BeInRange(-10, 10);
+ Assert.InRange(param.X, -10.0, 10.0);
}
var frCulture = new CultureInfo("fr-FR", false);
Thread.CurrentThread.CurrentCulture = frCulture;
- Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator.Should().Be(",");
+ Assert.Equal(",", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
for (int i = 0; i != 100; ++i)
{
var trialSettings = new TrialSettings()
@@ -415,7 +414,7 @@ public void Hyper_parameters_from_CFO_should_be_culture_invariant_string()
TrialId = i,
};
var param = cfo.Propose(trialSettings).AsType();
- param.X.Should().BeInRange(-10, 10);
+ Assert.InRange(param.X, -10.0, 10.0);
}
Thread.CurrentThread.CurrentCulture = originalCuture;
diff --git a/test/Microsoft.ML.Fairlearn.Tests/GridSearchTest.cs b/test/Microsoft.ML.Fairlearn.Tests/GridSearchTest.cs
index bf18066ba8..d4ea62bdf5 100644
--- a/test/Microsoft.ML.Fairlearn.Tests/GridSearchTest.cs
+++ b/test/Microsoft.ML.Fairlearn.Tests/GridSearchTest.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using FluentAssertions;
using Microsoft.Data.Analysis;
using Microsoft.ML.AutoML;
using Microsoft.ML.Fairlearn.AutoML;
@@ -29,7 +28,7 @@ public void Generate_binary_classification_lambda_search_space_test()
moment.LoadData(X, X["y_true"], X["sensitiveFeature"] as StringDataFrameColumn);
var searchSpace = Utilities.GenerateBinaryClassificationLambdaSearchSpace(moment, 5);
- searchSpace.Keys.Should().BeEquivalentTo("a_pos", "a_neg", "b_pos", "b_neg");
+ Assert.Equivalent(new[] { "a_pos", "a_neg", "b_pos", "b_neg" }, searchSpace.Keys, strict: true);
}
@@ -103,7 +102,7 @@ public void TestGridSearchTrialRunner2()
var bestResult = experiment.Run();
var model = bestResult.Model;
- bestResult.Metric.Should().BeGreaterThanOrEqualTo(0.4);
+ Assert.True(bestResult.Metric >= 0.4);
}
}
}
diff --git a/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj b/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj
index 9449caa039..93492748a2 100644
--- a/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj
+++ b/test/Microsoft.ML.Fairlearn.Tests/Microsoft.ML.Fairlearn.Tests.csproj
@@ -12,7 +12,6 @@
-
diff --git a/test/Microsoft.ML.SearchSpace.Tests/ChoiceOptionTest.cs b/test/Microsoft.ML.SearchSpace.Tests/ChoiceOptionTest.cs
index dab837e45b..7df9179bdd 100644
--- a/test/Microsoft.ML.SearchSpace.Tests/ChoiceOptionTest.cs
+++ b/test/Microsoft.ML.SearchSpace.Tests/ChoiceOptionTest.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using FluentAssertions;
using Microsoft.ML.SearchSpace.Option;
using Xunit;
using Xunit.Abstractions;
@@ -19,46 +18,46 @@ public ChoiceOptionTest(ITestOutputHelper output) : base(output)
public void Choice_option_sampling_from_uniform_space_test()
{
var option = new ChoiceOption("a", "b", "c");
- option.SampleFromFeatureSpace(new[] { 0.0 }).AsType().Should().Be("a");
- option.SampleFromFeatureSpace(new[] { 0.33 }).AsType().Should().Be("a");
- option.SampleFromFeatureSpace(new[] { 0.34 }).AsType().Should().Be("b");
- option.SampleFromFeatureSpace(new[] { 0.66 }).AsType().Should().Be("b");
- option.SampleFromFeatureSpace(new[] { 0.67 }).AsType().Should().Be("c");
- option.SampleFromFeatureSpace(new[] { 0.97 }).AsType().Should().Be("c");
- option.SampleFromFeatureSpace(new[] { 0.999999999 }).AsType().Should().Be("c");
- option.SampleFromFeatureSpace(new[] { 1.0 }).AsType().Should().Be("c");
+ Assert.Equal("a", option.SampleFromFeatureSpace(new[] { 0.0 }).AsType());
+ Assert.Equal("a", option.SampleFromFeatureSpace(new[] { 0.33 }).AsType());
+ Assert.Equal("b", option.SampleFromFeatureSpace(new[] { 0.34 }).AsType());
+ Assert.Equal("b", option.SampleFromFeatureSpace(new[] { 0.66 }).AsType());
+ Assert.Equal("c", option.SampleFromFeatureSpace(new[] { 0.67 }).AsType());
+ Assert.Equal("c", option.SampleFromFeatureSpace(new[] { 0.97 }).AsType());
+ Assert.Equal("c", option.SampleFromFeatureSpace(new[] { 0.999999999 }).AsType());
+ Assert.Equal("c", option.SampleFromFeatureSpace(new[] { 1.0 }).AsType());
}
[Fact]
public void Choice_option_with_one_value_sampling_from_uniform_space_test()
{
var option = new ChoiceOption("a");
- option.SampleFromFeatureSpace(new[] { 0.0 }).AsType().Should().Be("a");
- option.SampleFromFeatureSpace(new[] { 0.99 }).AsType().Should().Be("a");
+ Assert.Equal("a", option.SampleFromFeatureSpace(new[] { 0.0 }).AsType());
+ Assert.Equal("a", option.SampleFromFeatureSpace(new[] { 0.99 }).AsType());
}
[Fact]
public void Choice_option_mapping_to_uniform_space_test()
{
var option = new ChoiceOption("a", "b", "c");
- option.MappingToFeatureSpace(Parameter.FromString("a"))[0].Should().BeApproximately(0, 1e-5);
- option.MappingToFeatureSpace(Parameter.FromString("b"))[0].Should().BeApproximately(0.333333, 1e-5);
- option.MappingToFeatureSpace(Parameter.FromString("c"))[0].Should().BeApproximately(0.666666, 1e-5);
+ Assert.Equal(0, option.MappingToFeatureSpace(Parameter.FromString("a"))[0], tolerance: 1e-5);
+ Assert.Equal(0.333333, option.MappingToFeatureSpace(Parameter.FromString("b"))[0], tolerance: 1e-5);
+ Assert.Equal(0.666666, option.MappingToFeatureSpace(Parameter.FromString("c"))[0], tolerance: 1e-5);
option = new ChoiceOption("a", "b", "c", "d");
var parameter = option.SampleFromFeatureSpace(new[] { 0.5 });
- parameter.AsType().Should().Be("c");
- option.MappingToFeatureSpace(parameter).Should().Equal(0.5);
+ Assert.Equal("c", parameter.AsType());
+ Assert.Equal(new[] { 0.5 }, option.MappingToFeatureSpace(parameter));
}
[Fact]
public void Choice_option_dimension_should_be_0_if_contains_only_one_value()
{
var option = new ChoiceOption("b");
- option.FeatureSpaceDim.Should().Be(0);
- option.Default.Should().BeEquivalentTo(System.Array.Empty());
- option.SampleFromFeatureSpace(new double[0]).AsType().Should().Be("b");
- option.MappingToFeatureSpace(Parameter.FromString("b")).Should().BeEmpty();
+ Assert.Equal(0, option.FeatureSpaceDim);
+ Assert.Empty(option.Default);
+ Assert.Equal("b", option.SampleFromFeatureSpace(new double[0]).AsType());
+ Assert.Empty(option.MappingToFeatureSpace(Parameter.FromString("b")));
}
[Fact]
@@ -67,7 +66,7 @@ public void Choice_int_option_test()
var searchSpace = new SearchSpace();
searchSpace["choice"] = new ChoiceOption(1, 2, 3);
var parameter = searchSpace.SampleFromFeatureSpace(new[] { 0.5 });
- parameter["choice"].AsType().Should().Be(2);
+ Assert.Equal(2, parameter["choice"].AsType());
}
}
}
diff --git a/test/Microsoft.ML.SearchSpace.Tests/Microsoft.ML.SearchSpace.Tests.csproj b/test/Microsoft.ML.SearchSpace.Tests/Microsoft.ML.SearchSpace.Tests.csproj
index 866f365ab1..4c05009e04 100644
--- a/test/Microsoft.ML.SearchSpace.Tests/Microsoft.ML.SearchSpace.Tests.csproj
+++ b/test/Microsoft.ML.SearchSpace.Tests/Microsoft.ML.SearchSpace.Tests.csproj
@@ -7,7 +7,6 @@
-
diff --git a/test/Microsoft.ML.SearchSpace.Tests/ParameterTest.cs b/test/Microsoft.ML.SearchSpace.Tests/ParameterTest.cs
index e33d29e8e3..bea82d2336 100644
--- a/test/Microsoft.ML.SearchSpace.Tests/ParameterTest.cs
+++ b/test/Microsoft.ML.SearchSpace.Tests/ParameterTest.cs
@@ -9,7 +9,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.SearchSpace.Option;
using Xunit;
using Xunit.Abstractions;
@@ -41,7 +40,7 @@ public void Array_parameter_serialize_test()
Approvals.Verify(json);
parameter = JsonSerializer.Deserialize(json);
- parameter.AsType().Should().Equal("A", "B", "C");
+ Assert.Equal(new[] { "A", "B", "C" }, parameter.AsType());
}
[Fact]
@@ -50,35 +49,35 @@ public void Parameter_with_single_value_test()
var parameter = Parameter.FromInt(3);
// integer
- parameter.AsType().Should().Be(3);
+ Assert.Equal(3, parameter.AsType());
// double
parameter = Parameter.FromDouble(3.1415926);
- parameter.AsType().Should().Be(3.1415926);
+ Assert.Equal(3.1415926, parameter.AsType());
// float
parameter = Parameter.FromFloat(3.1415926F);
- parameter.AsType().Should().Be(3.1415926F);
+ Assert.Equal(3.1415926F, parameter.AsType());
// string
parameter = Parameter.FromString("abc");
- parameter.AsType().Should().Be("abc");
+ Assert.Equal("abc", parameter.AsType());
// bool
parameter = Parameter.FromBool(false);
- parameter.AsType().Should().BeFalse();
+ Assert.False(parameter.AsType());
// string[]
parameter = Parameter.FromIEnumerable(new[] { "a", "b", "c" });
- parameter.AsType().Should().BeEquivalentTo("a", "b", "c");
+ Assert.Equivalent(new[] { "a", "b", "c" }, parameter.AsType(), strict: true);
// enum
parameter = Parameter.FromEnum(JsonTokenType.None);
- parameter.AsType().Should().Be(JsonTokenType.None);
+ Assert.Equal(JsonTokenType.None, parameter.AsType());
// long
parameter = Parameter.FromLong(long.MaxValue);
- parameter.AsType().Should().Be(long.MaxValue);
+ Assert.Equal(long.MaxValue, parameter.AsType());
}
[Fact]
@@ -87,15 +86,15 @@ public void Nested_parameter_test()
var b = new B();
var parameter = Parameter.FromObject(b);
- parameter["Int"].AsType().Should().Be(0);
- parameter["Float"].AsType().Should().Be(1f);
- parameter["Double"].AsType().Should().Be(2);
- parameter["Bool"].AsType().Should().BeFalse();
- parameter["String"].AsType().Should().Be("String");
- parameter["Strings"].AsType().Should().BeEquivalentTo("A", "B", "C");
- parameter["JTokenType"].AsType().Should().Be(JsonTokenType.Null);
- parameter["A"].AsType().Strings.Should().BeEquivalentTo("A", "B", "C");
- parameter.AsType().Strings.Should().BeEquivalentTo("A", "B", "C");
+ Assert.Equal(0, parameter["Int"].AsType());
+ Assert.Equal(1f, parameter["Float"].AsType());
+ Assert.Equal(2.0, parameter["Double"].AsType());
+ Assert.False(parameter["Bool"].AsType());
+ Assert.Equal("String", parameter["String"].AsType());
+ Assert.Equivalent(new[] { "A", "B", "C" }, parameter["Strings"].AsType(), strict: true);
+ Assert.Equal(JsonTokenType.Null, parameter["JTokenType"].AsType());
+ Assert.Equivalent(new[] { "A", "B", "C" }, parameter["A"].AsType().Strings, strict: true);
+ Assert.Equivalent(new[] { "A", "B", "C" }, parameter.AsType().Strings, strict: true);
}
[Fact]
@@ -110,12 +109,12 @@ public void Nested_parameter_serialize_test()
Approvals.Verify(json);
parameter = JsonSerializer.Deserialize(json);
- parameter["Int"].AsType().Should().Be(0);
- parameter["Float"].AsType().Should().Be(1f);
- parameter["Double"].AsType().Should().Be(2);
- parameter["Bool"].AsType().Should().BeFalse();
- parameter["Strings"].AsType().Should().BeEquivalentTo("A", "B", "C");
- parameter["JTokenType"].AsType().Should().Be(JsonTokenType.Null);
+ Assert.Equal(0, parameter["Int"].AsType());
+ Assert.Equal(1f, parameter["Float"].AsType());
+ Assert.Equal(2.0, parameter["Double"].AsType());
+ Assert.False(parameter["Bool"].AsType());
+ Assert.Equivalent(new[] { "A", "B", "C" }, parameter["Strings"].AsType(), strict: true);
+ Assert.Equal(JsonTokenType.Null, parameter["JTokenType"].AsType());
json = JsonSerializer.Serialize(parameter, _settings);
Approvals.Verify(json);
}
@@ -129,7 +128,7 @@ public void Parameter_AsType_should_be_culture_invariant()
var ss = new SearchSpace();
ss.Add("_SampleSize", new UniformDoubleOption(10000, 20000));
var parameter = ss.SampleFromFeatureSpace(new[] { 0.5 });
- parameter["_SampleSize"].AsType().Should().Be(15000.0);
+ Assert.Equal(15000.0, parameter["_SampleSize"].AsType());
Thread.CurrentThread.CurrentCulture = originalCuture;
}
@@ -145,13 +144,13 @@ public void Parameter_equatable_test()
var paramB1 = Parameter.FromObject(b);
var paramB2 = Parameter.FromObject(b);
- (paramB1.Equals(paramB2)).Should().BeTrue();
+ Assert.True(paramB1.Equals(paramB2));
b.Bool = true;
paramB2 = Parameter.FromObject(b);
- (paramB1.Equals(paramB2)).Should().BeFalse();
- (paramB1.Equals(null)).Should().BeFalse();
+ Assert.False(paramB1.Equals(paramB2));
+ Assert.False(paramB1.Equals(null));
}
private class A
diff --git a/test/Microsoft.ML.SearchSpace.Tests/SearchSpaceTest.cs b/test/Microsoft.ML.SearchSpace.Tests/SearchSpaceTest.cs
index b62eccb49d..f651003e13 100644
--- a/test/Microsoft.ML.SearchSpace.Tests/SearchSpaceTest.cs
+++ b/test/Microsoft.ML.SearchSpace.Tests/SearchSpaceTest.cs
@@ -10,7 +10,6 @@
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
-using FluentAssertions;
using Microsoft.ML.SearchSpace.Option;
using Microsoft.ML.SearchSpace.Tuner;
using Microsoft.ML.Trainers;
@@ -41,18 +40,18 @@ public void SearchSpace_sample_from_feature_space_test()
var ss = new SearchSpace();
var param = ss.SampleFromFeatureSpace(new[] { 0.0, 0, 0, 0, 0, 0, 0 });
- param.ChoiceStr.Should().Be("a");
- param.UniformDouble.Should().Be(-1000);
- param.UniformFloat.Should().Be(-1000);
- param.UniformInt.Should().Be(-1000);
- param.ChoiceInt.Should().Be(1);
+ Assert.Equal("a", param.ChoiceStr);
+ Assert.Equal(-1000.0, param.UniformDouble);
+ Assert.Equal(-1000f, param.UniformFloat);
+ Assert.Equal(-1000, param.UniformInt);
+ Assert.Equal(1, param.ChoiceInt);
param = ss.SampleFromFeatureSpace(new[] { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 });
- param.ChoiceStr.Should().Be("c");
- param.UniformDouble.Should().Be(0);
- param.UniformFloat.Should().Be(0);
- param.ChoiceInt.Should().Be(3);
- param.UniformInt.Should().Be(0);
+ Assert.Equal("c", param.ChoiceStr);
+ Assert.Equal(0.0, param.UniformDouble);
+ Assert.Equal(0f, param.UniformFloat);
+ Assert.Equal(3, param.ChoiceInt);
+ Assert.Equal(0, param.UniformInt);
}
[Fact]
@@ -61,25 +60,25 @@ public void SearchSpace_mapping_to_feature_space_test()
var ss = new SearchSpace();
var param = ss.SampleFromFeatureSpace(new[] { 0.0, 0, 0, 0, 0, 0, 0 });
var features = ss.MappingToFeatureSpace(param);
- features.Should().Equal(0, 0, 0, 0, 0, 0, 0);
+ Assert.Equal(new double[] { 0, 0, 0, 0, 0, 0, 0 }, features);
param = ss.SampleFromFeatureSpace(new[] { 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5 });
features = ss.MappingToFeatureSpace(param);
- features.Should().Equal(0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5);
+ Assert.Equal(new[] { 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5 }, features);
}
[Fact]
public void Nest_search_space_mapping_to_feature_space_test()
{
var ss = new SearchSpace();
- ss.FeatureSpaceDim.Should().Be(9);
+ Assert.Equal(9, ss.FeatureSpaceDim);
var param = ss.SampleFromFeatureSpace(new[] { 0.0, 0, 0, 0, 0, 0, 0, 0, 0 });
var features = ss.MappingToFeatureSpace(param);
- features.Should().Equal(0, 0, 0, 0, 0, 0, 0, 0, 0);
+ Assert.Equal(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, features);
param = ss.SampleFromFeatureSpace(new[] { 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5 });
features = ss.MappingToFeatureSpace(param);
- features.Should().Equal(0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5);
+ Assert.Equal(new[] { 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5 }, features);
}
[Fact]
@@ -97,45 +96,45 @@ public void Nest_searchSpace_sample_from_feature_space_test()
};
var ss = new SearchSpace(option);
- ss.FeatureSpaceDim.Should().Be(9);
+ Assert.Equal(9, ss.FeatureSpaceDim);
var param = ss.SampleFromFeatureSpace(new[] { 0.0, 0, 0, 0, 0, 0, 0, 0, 0 });
- param.UniformDouble.Should().Be(-1000);
- param.UniformFloat.Should().Be(-1000);
- param.BasicSS.UniformInt.Should().Be(-1000);
- param.BasicSS.UniformDouble.Should().Be(-1000);
- param.BasicSS.UniformFloat.Should().Be(-1000);
- param.BasicSS.ChoiceStr.Should().Be("a");
- param.BasicSS.DefaultSearchSpace.Strings.Should().BeEquivalentTo("B", "C", "D");
- param.BasicSS.ChoiceBoolean.Should().BeTrue();
- param.BasicSS.JTokenType.Should().Be(JsonTokenType.None);
- param.BasicSS.ChoiceInt.Should().Be(1);
+ Assert.Equal(-1000.0, param.UniformDouble);
+ Assert.Equal(-1000f, param.UniformFloat);
+ Assert.Equal(-1000, param.BasicSS.UniformInt);
+ Assert.Equal(-1000.0, param.BasicSS.UniformDouble);
+ Assert.Equal(-1000f, param.BasicSS.UniformFloat);
+ Assert.Equal("a", param.BasicSS.ChoiceStr);
+ Assert.Equivalent(new[] { "B", "C", "D" }, param.BasicSS.DefaultSearchSpace.Strings, strict: true);
+ Assert.True(param.BasicSS.ChoiceBoolean);
+ Assert.Equal(JsonTokenType.None, param.BasicSS.JTokenType);
+ Assert.Equal(1, param.BasicSS.ChoiceInt);
param = ss.SampleFromFeatureSpace(new[] { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 });
- param.UniformDouble.Should().Be(0);
- param.UniformFloat.Should().Be(0);
- param.BasicSS.UniformInt.Should().Be(0);
- param.BasicSS.UniformDouble.Should().Be(0);
- param.BasicSS.UniformFloat.Should().Be(0);
- param.BasicSS.ChoiceStr.Should().Be("c");
- param.BasicSS.DefaultSearchSpace.Strings.Should().BeEquivalentTo("B", "C", "D");
- param.BasicSS.ChoiceInt.Should().Be(3);
- param.BasicSS.ChoiceBoolean.Should().BeFalse();
- param.BasicSS.JTokenType.Should().Be(JsonTokenType.StartArray);
+ Assert.Equal(0.0, param.UniformDouble);
+ Assert.Equal(0f, param.UniformFloat);
+ Assert.Equal(0, param.BasicSS.UniformInt);
+ Assert.Equal(0.0, param.BasicSS.UniformDouble);
+ Assert.Equal(0f, param.BasicSS.UniformFloat);
+ Assert.Equal("c", param.BasicSS.ChoiceStr);
+ Assert.Equivalent(new[] { "B", "C", "D" }, param.BasicSS.DefaultSearchSpace.Strings, strict: true);
+ Assert.Equal(3, param.BasicSS.ChoiceInt);
+ Assert.False(param.BasicSS.ChoiceBoolean);
+ Assert.Equal(JsonTokenType.StartArray, param.BasicSS.JTokenType);
}
[Fact]
public void Search_space_add_option_test()
{
var ss = new SearchSpace();
- ss.FeatureSpaceDim.Should().Be(0);
+ Assert.Equal(0, ss.FeatureSpaceDim);
ss.Add("A", new UniformIntOption(-1000, 1000));
- ss.FeatureSpaceDim.Should().Be(1);
+ Assert.Equal(1, ss.FeatureSpaceDim);
var param = ss.SampleFromFeatureSpace(new[] { 0.5 });
- param["A"].AsType().Should().Be(0);
+ Assert.Equal(0, param["A"].AsType());
}
[Fact]
@@ -143,20 +142,20 @@ public void Search_space_remove_option_test()
{
var option = new BasicSearchSpace();
var ss = new SearchSpace(option);
- ss.FeatureSpaceDim.Should().Be(7);
+ Assert.Equal(7, ss.FeatureSpaceDim);
- ss.Remove("UniformInt").Should().BeTrue();
- ss.FeatureSpaceDim.Should().Be(6);
- ss.Keys.Should().BeEquivalentTo("ChoiceStr", "UniformDouble", "UniformFloat", "ChoiceBoolean", "JTokenType", "ChoiceInt");
+ Assert.True(ss.Remove("UniformInt"));
+ Assert.Equal(6, ss.FeatureSpaceDim);
+ Assert.Equivalent(new[] { "ChoiceStr", "UniformDouble", "UniformFloat", "ChoiceBoolean", "JTokenType", "ChoiceInt" }, ss.Keys, strict: true);
var parameter = ss.SampleFromFeatureSpace(new double[] { 0, 0, 0, 0, 0, 0 });
- parameter.DefaultSearchSpace.Strings.Should().BeEquivalentTo("A", "B", "C");
- parameter.DefaultSearchSpace.String.Should().BeNullOrEmpty();
- parameter.ChoiceStr.Should().Be("a");
- parameter.ChoiceBoolean.Should().BeTrue();
- parameter.JTokenType.Should().Be(JsonTokenType.None);
- parameter.ChoiceInt.Should().Be(1);
+ Assert.Equivalent(new[] { "A", "B", "C" }, parameter.DefaultSearchSpace.Strings, strict: true);
+ Assert.True(string.IsNullOrEmpty(parameter.DefaultSearchSpace.String));
+ Assert.Equal("a", parameter.ChoiceStr);
+ Assert.True(parameter.ChoiceBoolean);
+ Assert.Equal(JsonTokenType.None, parameter.JTokenType);
+ Assert.Equal(1, parameter.ChoiceInt);
}
[Fact]
@@ -166,15 +165,15 @@ public void Search_space_default_value_test()
var defaultTuner = new DefaultValueTuner(ss);
var param = defaultTuner.Propose().AsType();
- param.UniformDouble.Should().Be(0);
- param.UniformFloat.Should().Be(0);
- param.BasicSS.UniformInt.Should().Be(0);
- param.BasicSS.UniformDouble.Should().Be(0);
- param.BasicSS.UniformFloat.Should().Be(0);
- param.BasicSS.ChoiceStr.Should().Be("a");
- param.BasicSS.ChoiceBoolean.Should().BeTrue();
- param.BasicSS.JTokenType.Should().Be(JsonTokenType.Null);
- param.BasicSS.ChoiceInt.Should().Be(1);
+ Assert.Equal(0.0, param.UniformDouble);
+ Assert.Equal(0f, param.UniformFloat);
+ Assert.Equal(0, param.BasicSS.UniformInt);
+ Assert.Equal(0.0, param.BasicSS.UniformDouble);
+ Assert.Equal(0f, param.BasicSS.UniformFloat);
+ Assert.Equal("a", param.BasicSS.ChoiceStr);
+ Assert.True(param.BasicSS.ChoiceBoolean);
+ Assert.Equal(JsonTokenType.Null, param.BasicSS.JTokenType);
+ Assert.Equal(1, param.BasicSS.ChoiceInt);
}
[Fact]
@@ -191,26 +190,26 @@ public void Search_space_default_search_space_test()
var ss = new SearchSpace(defaultSearchSpace);
var param = ss.SampleFromFeatureSpace(new double[0]);
- param.Int.Should().Be(10);
- param.Float.Should().Be(0f);
- param.Double.Should().Be(0);
- param.Bool.Should().BeTrue();
- param.String.Should().Be("String");
- param.Strings.Should().BeEquivalentTo("A", "B", "C");
- param.JTokenType.Should().Be(JsonTokenType.Null);
- param.NullString.Should().BeNull();
- ss.FeatureSpaceDim.Should().Be(0);
- ss.MappingToFeatureSpace(param).Should().HaveCount(0);
+ Assert.Equal(10, param.Int);
+ Assert.Equal(0f, param.Float);
+ Assert.Equal(0.0, param.Double);
+ Assert.True(param.Bool);
+ Assert.Equal("String", param.String);
+ Assert.Equivalent(new[] { "A", "B", "C" }, param.Strings, strict: true);
+ Assert.Equal(JsonTokenType.Null, param.JTokenType);
+ Assert.Null(param.NullString);
+ Assert.Equal(0, ss.FeatureSpaceDim);
+ Assert.Empty(ss.MappingToFeatureSpace(param));
}
[Fact]
public void Search_space_hash_code_test()
{
var ss = new SearchSpace();
- ss.GetHashCode().Should().Be(2005165306);
+ Assert.Equal(2005165306, ss.GetHashCode());
ss.Remove("UniformInt");
- ss.GetHashCode().Should().Be(125205970);
+ Assert.Equal(125205970, ss.GetHashCode());
}
[Fact]
@@ -224,18 +223,18 @@ public void SearchSpace_sampling_from_uniform_space_test()
anotherNestOption["int"] = new UniformIntOption(2, 3);
searchSpace["nestOption"] = anotherNestOption;
- searchSpace.FeatureSpaceDim.Should().Be(4);
+ Assert.Equal(4, searchSpace.FeatureSpaceDim);
var parameter = searchSpace.SampleFromFeatureSpace(new double[] { 0, 0, 0, 0 });
- parameter["nestOption"]["choice"].AsType().Should().Be("d");
- parameter["nestOption"]["int"].AsType().Should().Be(2);
- parameter["choice"].AsType().Should().Be("a");
- parameter["int"].AsType().Should().Be(0);
+ Assert.Equal("d", parameter["nestOption"]["choice"].AsType());
+ Assert.Equal(2, parameter["nestOption"]["int"].AsType());
+ Assert.Equal("a", parameter["choice"].AsType());
+ Assert.Equal(0, parameter["int"].AsType());
parameter = searchSpace.SampleFromFeatureSpace(new double[] { 1, 1, 1, 1 });
- parameter["nestOption"]["choice"].AsType().Should().Be("e");
- parameter["nestOption"]["int"].AsType().Should().Be(3);
- parameter["choice"].AsType().Should().Be("c");
- parameter["int"].AsType().Should().Be(1);
+ Assert.Equal("e", parameter["nestOption"]["choice"].AsType());
+ Assert.Equal(3, parameter["nestOption"]["int"].AsType());
+ Assert.Equal("c", parameter["choice"].AsType());
+ Assert.Equal(1, parameter["int"].AsType());
}
[Fact]
@@ -248,7 +247,7 @@ public void SearchSpace_mapping_to_uniform_space_test()
var parameter = Parameter.CreateNestedParameter();
parameter["choice"] = Parameter.FromString("a");
parameter["int"] = Parameter.FromInt(0);
- searchSpace.MappingToFeatureSpace(parameter).Should().Equal(0, 0);
+ Assert.Equal(new double[] { 0, 0 }, searchSpace.MappingToFeatureSpace(parameter));
}
[Fact]
@@ -262,17 +261,17 @@ public void SearchSpace_mapping_order_test()
// changing of the first dimension should be reflected in option "a"
var parameter = searchSpace.SampleFromFeatureSpace(new double[] { 0, 0.5, 0.5 });
- parameter["a"].AsType().Should().Be(0);
+ Assert.Equal(0, parameter["a"].AsType());
parameter = searchSpace.SampleFromFeatureSpace(new double[] { 1, 0.5, 0.5 });
- parameter["a"].AsType().Should().Be(1);
+ Assert.Equal(1, parameter["a"].AsType());
searchSpace.Remove("a");
// the first dimension should be option "b"
parameter = searchSpace.SampleFromFeatureSpace(new double[] { 0, 0.5 });
- parameter["b"].AsType().Should().Be(1);
+ Assert.Equal(1, parameter["b"].AsType());
parameter = searchSpace.SampleFromFeatureSpace(new double[] { 1, 0.5 });
- parameter["b"].AsType().Should().Be(2);
+ Assert.Equal(2, parameter["b"].AsType());
}
[Fact]
diff --git a/test/Microsoft.ML.SearchSpace.Tests/UniformNumericOptionTests.cs b/test/Microsoft.ML.SearchSpace.Tests/UniformNumericOptionTests.cs
index e2ca74f4a9..7cb3a902e9 100644
--- a/test/Microsoft.ML.SearchSpace.Tests/UniformNumericOptionTests.cs
+++ b/test/Microsoft.ML.SearchSpace.Tests/UniformNumericOptionTests.cs
@@ -4,7 +4,6 @@
using System;
using System.Linq;
-using FluentAssertions;
using Microsoft.ML.SearchSpace.Option;
using Xunit;
using Xunit.Abstractions;
@@ -25,7 +24,7 @@ public void Uniform_integer_option_sampling_from_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => i * 0.1);
var sampleOutputs = sampleInputs.Select(i => option.SampleFromFeatureSpace(new[] { i }));
- sampleOutputs.Select(x => x.AsType()).Should().Equal(0, 10, 20, 30, 40, 50, 60, 70, 80, 90);
+ Assert.Equal(new[] { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 }, sampleOutputs.Select(x => x.AsType()));
}
[Fact]
@@ -36,7 +35,7 @@ public void Uniform_log_integer_option_sampling_from_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => i * 0.1);
var sampleOutputs = sampleInputs.Select(i => option.SampleFromFeatureSpace(new[] { i }));
- sampleOutputs.Select(x => x.AsType()).Should().Equal(1, 2, 4, 8, 16, 32, 64, 128, 256, 512);
+ Assert.Equal(new[] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, sampleOutputs.Select(x => x.AsType()));
}
[Fact]
@@ -47,14 +46,14 @@ public void Uniform_integer_option_mapping_to_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => Parameter.FromInt(i * 10));
var sampleOutputs = sampleInputs.Select(i => option.MappingToFeatureSpace(i)[0]);
- sampleOutputs.Should().Equal(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9);
+ Assert.Equal(new[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 }, sampleOutputs);
}
[Fact]
public void Uniform_integer_option_mapping_to_uniform_space_test_2()
{
var option = new UniformIntOption(20, 1024, defaultValue: 20, logBase: true);
- option.SampleFromFeatureSpace(new double[] { 0.0 }).AsType().Should().Be(20);
+ Assert.Equal(20, option.SampleFromFeatureSpace(new double[] { 0.0 }).AsType());
}
[Fact]
@@ -67,7 +66,7 @@ public void Uniform_log_integer_option_mapping_to_uniform_space_test()
foreach (var i in Enumerable.Range(0, 10))
{
- sampleOutputs[i].Should().BeApproximately(0.1 * i, 0.0001);
+ Assert.Equal(0.1 * i, sampleOutputs[i], tolerance: 0.0001);
}
}
@@ -79,9 +78,8 @@ public void Uniform_double_option_sampling_from_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => i * 0.1);
var sampleOutputs = sampleInputs.Select(i => option.SampleFromFeatureSpace(new[] { i }));
- sampleOutputs.Select((x, i) => (x.AsType(), i * 10))
- .All((x) => Math.Abs(x.Item1 - x.Item2) < 1e-5)
- .Should().BeTrue();
+ Assert.True(sampleOutputs.Select((x, i) => (x.AsType(), i * 10))
+ .All((x) => Math.Abs(x.Item1 - x.Item2) < 1e-5));
}
[Fact]
@@ -92,9 +90,8 @@ public void Uniform_log_double_option_sampling_from_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => i * 0.1);
var sampleOutputs = sampleInputs.Select(i => option.SampleFromFeatureSpace(new[] { i }));
- sampleOutputs.Select((x, i) => (x.AsType(), Math.Pow(2, i)))
- .All((x) => Math.Abs(x.Item1 - x.Item2) < 1e-5)
- .Should().BeTrue();
+ Assert.True(sampleOutputs.Select((x, i) => (x.AsType(), Math.Pow(2, i)))
+ .All((x) => Math.Abs(x.Item1 - x.Item2) < 1e-5));
}
[Fact]
@@ -105,7 +102,7 @@ public void Uniform_double_option_mapping_to_uniform_space_test()
var sampleInputs = Enumerable.Range(0, 10).Select(i => Parameter.FromDouble(i * 10.0));
var sampleOutputs = sampleInputs.Select(i => option.MappingToFeatureSpace(i)[0]);
- sampleOutputs.Should().Equal(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9);
+ Assert.Equal(new[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 }, sampleOutputs);
}
[Fact]
@@ -118,7 +115,7 @@ public void Uniform_log_double_option_mapping_to_uniform_space_test()
foreach (var i in Enumerable.Range(0, 10))
{
- sampleOutputs[i][0].Should().BeApproximately(0.1 * i, 1e-5);
+ Assert.Equal(0.1 * i, sampleOutputs[i][0], tolerance: 1e-5);
}
}
@@ -126,9 +123,9 @@ public void Uniform_log_double_option_mapping_to_uniform_space_test()
public void Uniform_log_double_option_round_up_test()
{
var option = new UniformDoubleOption(2e-10, 1, defaultValue: 2e-10, logBase: true);
- option.Default.Should().Equal(0);
- option.SampleFromFeatureSpace(option.Default).AsType().Should().Be(2e-10);
- option.SampleFromFeatureSpace(new[] { 1.0 }).AsType().Should().Be(1.0);
+ Assert.Equal(new[] { 0.0 }, option.Default);
+ Assert.Equal(2e-10, option.SampleFromFeatureSpace(option.Default).AsType());
+ Assert.Equal(1.0, option.SampleFromFeatureSpace(new[] { 1.0 }).AsType());
}
}
}
diff --git a/test/Microsoft.ML.Tests/DatabaseLoaderTests.cs b/test/Microsoft.ML.Tests/DatabaseLoaderTests.cs
index 3291443422..414a8c40e4 100644
--- a/test/Microsoft.ML.Tests/DatabaseLoaderTests.cs
+++ b/test/Microsoft.ML.Tests/DatabaseLoaderTests.cs
@@ -9,7 +9,6 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
-using FluentAssertions;
using Microsoft.ML.Data;
using Microsoft.ML.RunTests;
using Microsoft.ML.TestFramework;
@@ -320,12 +319,12 @@ public void TestLoadDatetimeColumnWithNullValue()
var source = new DatabaseSource(SQLiteFactory.Instance, connectionString, "SELECT datetime FROM Datetime");
var data = loader.Load(source);
var datetimes = data.GetColumn("datetime").ToArray();
- datetimes.Count().Should().Be(2);
// Convert null value to DateTime.MinValue, aka 0001-01-01 00:00:00
// This is the default behavior of TextLoader as well.
- datetimes[0].Should().Be(DateTime.MinValue);
- datetimes[1].Should().Be(new DateTime(2018, 1, 1, 0, 0, 0));
+ Assert.Collection(datetimes,
+ datetime => Assert.Equal(DateTime.MinValue, datetime),
+ datetime => Assert.Equal(new DateTime(2018, 1, 1, 0, 0, 0), datetime));
}
///
diff --git a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj
index 0ca7369d95..d9b79b93b5 100644
--- a/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj
+++ b/test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj
@@ -52,7 +52,6 @@
-
diff --git a/test/Microsoft.ML.Tests/TrainerEstimators/OneDalEstimators.cs b/test/Microsoft.ML.Tests/TrainerEstimators/OneDalEstimators.cs
index 713edbae31..50edbd48ef 100644
--- a/test/Microsoft.ML.Tests/TrainerEstimators/OneDalEstimators.cs
+++ b/test/Microsoft.ML.Tests/TrainerEstimators/OneDalEstimators.cs
@@ -8,7 +8,6 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.Extensions.DependencyModel;
using Microsoft.ML.Calibrators;
diff --git a/test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs b/test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs
index 19788437cc..abf0102824 100644
--- a/test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs
+++ b/test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs
@@ -19,7 +19,6 @@
using Microsoft.ML.Trainers.LightGbm;
using Microsoft.ML.Transforms;
using Xunit;
-using FluentAssertions;
using System.IO;
namespace Microsoft.ML.Tests.TrainerEstimators
@@ -1107,8 +1106,7 @@ public void FastTreeMultiClassificationCancellationTest()
}
};
- var action = () => estimator.Fit(dataView);
- action.Should().Throw();
+ Assert.ThrowsAny(() => estimator.Fit(dataView));
}
[LightGBMFact]
@@ -1161,8 +1159,7 @@ public void LightGbmBinaryClassificationCancellationTest()
UseCategoricalSplit = true
}));
- var action = () => trainer.Fit(dataView);
- action.Should().Throw();
+ Assert.ThrowsAny(() => trainer.Fit(dataView));
}
[LightGBMFact]
@@ -1189,8 +1186,7 @@ public void LightGbmMultiClassificationCancellationTest()
UseCategoricalSplit = true
}));
- var action = () => trainer.Fit(dataView);
- action.Should().Throw();
+ Assert.ThrowsAny(() => trainer.Fit(dataView));
}
}
}