コード例 #1
0
        public void CorrectParse()
        {
            var histogramService = new HistogramSorterService();

            // Get the directory in which the test files are contained.
            var pathToHistogramFiles = $"{Directory.GetCurrentDirectory()}/../../../{TestFilesFolder}";

            // Parse the files in the test directory.
            var parseOutput = histogramService.ParseHistograms(pathToHistogramFiles);

            var testFileNames =
                Directory
                .GetFiles(pathToHistogramFiles)
                .Select(Path.GetFileNameWithoutExtension)
                .ToList();

            var imageIds =
                parseOutput
                .Select(histogram => histogram.ImageId)
                .ToList();

            Assert.True(testFileNames.Count == NumberOfHistogramsInTestFolder);
            Assert.True(testFileNames.Count == parseOutput.Count);
            foreach (var testFileName in testFileNames)
            {
                Assert.Contains(testFileName, imageIds);
            }

            foreach (var colorHistogram in parseOutput)
            {
                Assert.True(colorHistogram.RedHistogram.Count == 16);
                Assert.True(colorHistogram.GreenHistogram.Count == 16);
                Assert.True(colorHistogram.BlueHistogram.Count == 16);
            }
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var configService       = new GlobalConfigService();
            var globalConfig        = configService.LoadConfig(Configuration);
            var userSessionsManager = new UserSessionsManager();

            var labelsService    = new LabelSorterService();
            var histogramService = new HistogramSorterService();

            var imageLabelsPath     = Configuration["FilePaths:ImageLabelsPath"];
            var colorHistogramsPath = Configuration["FilePaths:ColorHistogramFiles"];

            var imageLabelsWrapper = new LoadedImageLabelsWrapper(labelsService.ParseLabels(imageLabelsPath));
            var histogramsWrapper  = new LoadedHistogramsWrapper(histogramService.ParseHistograms(colorHistogramsPath));

            services.AddSingleton(globalConfig);
            services.AddSingleton(configService);
            services.AddSingleton(userSessionsManager);
            services.AddSingleton(labelsService);
            services.AddSingleton(histogramService);
            services.AddSingleton(imageLabelsWrapper);
            services.AddSingleton(histogramsWrapper);

            services.AddRazorPages();
        }
コード例 #3
0
        public void IncorrectArgumentImageSelection()
        {
            var histogramService     = new HistogramSorterService();
            var pathToHistogramFiles = $"{Directory.GetCurrentDirectory()}/../../../{TestFilesFolder}";
            var colorHistograms      = histogramService.ParseHistograms(pathToHistogramFiles);

            try
            {
                histogramService.SelectRandomImages(NumberOfTestImagesForArgumentExc, colorHistograms);
            }
            catch (ArgumentException)
            {
                Assert.True(true);
            }
            catch (Exception)
            {
                Assert.True(false);
            }
        }
コード例 #4
0
        public void CorrectImageSelection()
        {
            var histogramService     = new HistogramSorterService();
            var pathToHistogramFiles = $"{Directory.GetCurrentDirectory()}/../../../{TestFilesFolder}";
            var colorHistograms      = histogramService.ParseHistograms(pathToHistogramFiles);

            var presentedImages =
                histogramService.SelectRandomImages(NumberOfImagesToPresent, colorHistograms);

            Assert.True(presentedImages.Count == NumberOfImagesToPresent);
            for (var i = presentedImages.Count - 1; i >= 0; i--)
            {
                for (var j = i - 1; j >= 0; j--)
                {
                    Assert.True(
                        presentedImages[i].ImageId != presentedImages[j].ImageId,
                        $"{presentedImages[i].ImageId} matches {presentedImages[j].ImageId}"
                        );
                }
                presentedImages.RemoveAt(i);
            }
        }