コード例 #1
0
        public void ConvertGenerationGenomeCompositionReturnsCorrectOutput()
        {
            var parameterTree = GrayBoxUtilsTest.CreateDummyParameterTree();

            // Read generation genome composition from file and convert it.
            GrayBoxUtils.TryToReadGenerationCompositionFromFile(
                GrayBoxUtilsTest.GenerationGenomeCompositionFile,
                out var generationGenomeComposition).ShouldBeTrue();
            var(convertedGenerationGenomeComposition, genomeStringDictionary) =
                GrayBoxUtils.ConvertGenerationGenomeComposition(generationGenomeComposition, parameterTree);

            // Check counts.
            genomeStringDictionary.Count.ShouldBe(9);
            convertedGenerationGenomeComposition.Count.ShouldBe(3);
            convertedGenerationGenomeComposition[0].Count.ShouldBe(9);
            convertedGenerationGenomeComposition[1].Count.ShouldBe(9);
            convertedGenerationGenomeComposition[2].Count.ShouldBe(9);

            // Check all elements.
            var flatenGenerationGenomeComposition          = generationGenomeComposition.SelectMany(x => x).ToList();
            var flatenConvertedGenerationGenomeComposition = convertedGenerationGenomeComposition.SelectMany(x => x).ToList();

            for (var index = 0; index < flatenConvertedGenerationGenomeComposition.Count; index++)
            {
                genomeStringDictionary[flatenConvertedGenerationGenomeComposition[index]].ShouldBe(flatenGenerationGenomeComposition[index]);
            }
        }
コード例 #2
0
        public void MoveOldDataLogFilesMovesCorrectFiles(bool tuningStartsFromExistingStatus)
        {
            // Declare target directory.
            var pathToTargetDirectory = Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "OldDataLogFiles");

            Directory.Exists(pathToTargetDirectory).ShouldBeFalse();

            // Create files.
            var postTuningDataLogFile =
                new FileInfo(
                    Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "dataLog_generation_-1_process_1_id_0_Finished.csv"));
            var pastDataLogFile = new FileInfo(
                Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "dataLog_generation_0_process_1_id_0_Finished.csv"));
            var futureDataLogFile =
                new FileInfo(
                    Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "dataLog_generation_1_process_1_id_0_Finished.csv"));
            var brokenDataLogFile = new FileInfo(Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "dataLog.csv"));

            GrayBoxUtilsTest.CreateFileAndCloseIt(postTuningDataLogFile.FullName);
            GrayBoxUtilsTest.CreateFileAndCloseIt(pastDataLogFile.FullName);
            GrayBoxUtilsTest.CreateFileAndCloseIt(futureDataLogFile.FullName);
            GrayBoxUtilsTest.CreateFileAndCloseIt(brokenDataLogFile.FullName);

            // Move old data log files to target directory.
            GrayBoxUtils.MoveOldDataLogFiles(
                GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName,
                pathToTargetDirectory,
                tuningStartsFromExistingStatus,
                0);

            // Check the data record directory.
            File.Exists(postTuningDataLogFile.FullName).ShouldBeFalse();
            File.Exists(futureDataLogFile.FullName).ShouldBeFalse();
            File.Exists(brokenDataLogFile.FullName).ShouldBeTrue();
            if (tuningStartsFromExistingStatus)
            {
                File.Exists(pastDataLogFile.FullName).ShouldBeTrue();
            }
            else
            {
                File.Exists(pastDataLogFile.FullName).ShouldBeFalse();
            }

            // Check the target directory.
            Directory.Exists(pathToTargetDirectory).ShouldBeTrue();
            File.Exists(Path.Combine(pathToTargetDirectory, postTuningDataLogFile.Name)).ShouldBeTrue();
            File.Exists(Path.Combine(pathToTargetDirectory, futureDataLogFile.Name)).ShouldBeTrue();
            File.Exists(Path.Combine(pathToTargetDirectory, brokenDataLogFile.Name)).ShouldBeFalse();
            if (tuningStartsFromExistingStatus)
            {
                File.Exists(Path.Combine(pathToTargetDirectory, pastDataLogFile.Name)).ShouldBeFalse();
            }
            else
            {
                File.Exists(Path.Combine(pathToTargetDirectory, pastDataLogFile.Name)).ShouldBeTrue();
            }
        }
コード例 #3
0
        public void TryToReadDataRecordsFromFileWorksForValidFiles()
        {
            var targetAlgorithmFactory =
                new TargetAlgorithmFactoryTest.DummyTargetAlgorithmFactory <
                    TargetAlgorithmFactoryTest.DummyTargetAlgorithm <TestInstance, RuntimeResult>, TestInstance, RuntimeResult>();

            GrayBoxUtils.TryToReadDataRecordsFromFile(targetAlgorithmFactory, GrayBoxUtilsTest.ValidDataLogFile, out var dataRecords).ShouldBeTrue();

            // Check count.
            dataRecords.Count.ShouldBe(1);

            // Check all values.
            GrayBoxUtilsTest.CheckDataRecordValues(dataRecords[0]);
        }
コード例 #4
0
        public void TryToMoveFileMovesFile()
        {
            GrayBoxUtilsTest.DummyTestDataRecordDirectory.GetFiles().Length.ShouldBe(0);

            var file       = new FileInfo(Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "file.csv"));
            var targetFile = new FileInfo(Path.Combine(GrayBoxUtilsTest.DummyTestDataRecordDirectory.FullName, "targetFile.csv"));

            GrayBoxUtilsTest.CreateFileAndCloseIt(file.FullName);

            GrayBoxUtilsTest.DummyTestDataRecordDirectory.GetFiles().Length.ShouldBe(1);
            File.Exists(file.FullName).ShouldBeTrue();
            File.Exists(targetFile.FullName).ShouldBeFalse();

            GrayBoxUtils.TryToMoveFile(file, targetFile);

            GrayBoxUtilsTest.DummyTestDataRecordDirectory.GetFiles().Length.ShouldBe(1);
            File.Exists(file.FullName).ShouldBeFalse();
            File.Exists(targetFile.FullName).ShouldBeTrue();
        }
コード例 #5
0
        public void TryToReadDataRecordsFromDirectoryReturnsCorrectOutput()
        {
            var targetAlgorithmFactory =
                new TargetAlgorithmFactoryTest.DummyTargetAlgorithmFactory <
                    TargetAlgorithmFactoryTest.DummyTargetAlgorithm <TestInstance, RuntimeResult>, TestInstance, RuntimeResult>();

            GrayBoxUtils.TryToReadDataRecordsFromDirectory(
                targetAlgorithmFactory,
                GrayBoxUtilsTest.PathToRealTestDataDirectory,
                0,
                1,
                out var dataRecords)
            .ShouldBeTrue();

            // Check count.
            dataRecords.Count.ShouldBe(2);

            // Check all values.
            foreach (var dataRecord in dataRecords)
            {
                GrayBoxUtilsTest.CheckDataRecordValues(dataRecord);
            }
        }