diff --git a/Optuna/Study/Study.cs b/Optuna/Study/Study.cs index c65dc5e4..4db4d7bb 100644 --- a/Optuna/Study/Study.cs +++ b/Optuna/Study/Study.cs @@ -105,7 +105,7 @@ public static StudySummary[] GetAllStudySummaries(IOptunaStorage storage) IEnumerable completeTrials = allTrials.Where(trial => trial.State == TrialState.COMPLETE); StudyDirection direction = StudyDirection.NotSet; - StudyDirection[] directions = Array.Empty(); + StudyDirection[] directions = null; Trial.Trial bestTrial = null; if (studies[i].Directions.Length == 1) { diff --git a/Optuna/Study/StudySummary.cs b/Optuna/Study/StudySummary.cs index a927d919..cbe46b28 100644 --- a/Optuna/Study/StudySummary.cs +++ b/Optuna/Study/StudySummary.cs @@ -66,10 +66,6 @@ public StudyDirection[] Directions { get { - if (_directions.Length == 1) - { - throw new InvalidOperationException("The study has only one direction."); - } return _directions; } } diff --git a/OptunaTests/Storage/StorageSameBevaviorTests.cs b/OptunaTests/Storage/StorageSameBevaviorTests.cs index dbd79631..1b60523e 100644 --- a/OptunaTests/Storage/StorageSameBevaviorTests.cs +++ b/OptunaTests/Storage/StorageSameBevaviorTests.cs @@ -7,7 +7,7 @@ namespace Optuna.Storage.Tests { public class StorageSameBehaviorTests { - [Theory()] + [Theory] [InlineData(@"TestFile/sqlite.db", "sqlite")] [InlineData(@"TestFile/journal.log", "log")] public void StorageLoadTest(string path, string type) diff --git a/OptunaTests/Study/StudySummaryTests.cs b/OptunaTests/Study/StudySummaryTests.cs new file mode 100644 index 00000000..dec7e9a2 --- /dev/null +++ b/OptunaTests/Study/StudySummaryTests.cs @@ -0,0 +1,29 @@ +using System; + +using Optuna.Storage; +using Optuna.Storage.Journal; +using Optuna.Storage.RDB; + +using Xunit; + +namespace Optuna.Study.Tests +{ + public class StudySummaryTests + { + [Theory] + [InlineData(@"TestFile/sqlite.db", "sqlite")] + [InlineData(@"TestFile/journal.log", "log")] + public void StorageLoadStudySummaryTest(string path, string type) + { + IOptunaStorage storage = type == "sqlite" + ? new SqliteStorage(path) + : (IOptunaStorage)new JournalStorage(path); + StudySummary[] summary = Study.GetAllStudySummaries(storage); + Assert.Equal(3, summary.Length); + Assert.Equal(2, summary[0].Directions.Length); + Assert.Throws(() => summary[0].Direction); + Assert.Equal(StudyDirection.Minimize, summary[1].Direction); + Assert.Equal(3, summary[2].Directions.Length); + } + } +}