예제 #1
0
        public void ClearAssemblyResult_Always_ClearsResultOnControl()
        {
            // Setup
            var random = new Random(39);

            using (var resultControl = new AssessmentSectionAssemblyResultControl())
            {
                var result = new AssessmentSectionAssemblyResult(random.NextDouble(),
                                                                 random.NextEnumValue <AssessmentSectionAssemblyGroup>());
                resultControl.SetAssemblyResult(result);

                // Precondition
                BorderedLabel groupLabel = GetGroupLabel(resultControl);
                AssertGroupLabel(result.AssemblyGroup, groupLabel);

                BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
                AssertProbabilityLabel(result.Probability, probabilityLabel);

                // Call
                resultControl.ClearAssemblyResult();

                // Assert
                Assert.AreEqual("-", groupLabel.Text);
                Assert.AreEqual(Color.White, groupLabel.BackColor);

                Assert.AreEqual("-", probabilityLabel.Text);
            }
        }
        public void AssembleAssessmentSection_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
        {
            // Setup
            var    random = new Random(21);
            double signalFloodingProbability           = random.NextDouble();
            double maximumAllowableFloodingProbability = signalFloodingProbability + 1e-3;

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
                var assemblyProbability = new Probability(random.NextDouble());
                var assemblyGroup       = random.NextEnumValue <EAssessmentGrade>();
                kernel.AssemblyProbability = assemblyProbability;
                kernel.AssemblyGroup       = assemblyGroup;

                var calculator = new AssessmentSectionAssemblyCalculator(factory);

                // Call
                AssessmentSectionAssemblyResultWrapper resultWrapper = calculator.AssembleAssessmentSection(
                    Enumerable.Empty <double>(), maximumAllowableFloodingProbability, signalFloodingProbability);

                // Assert
                AssessmentSectionAssemblyResult result = resultWrapper.AssemblyResult;
                Assert.AreEqual(assemblyProbability, result.Probability);
                Assert.AreEqual(AssessmentSectionAssemblyGroupCreator.CreateAssessmentSectionAssemblyGroup(assemblyGroup),
                                result.AssemblyGroup);
                Assert.AreEqual(AssemblyMethod.BOI2A1, resultWrapper.ProbabilityMethod);
                Assert.AreEqual(AssemblyMethod.BOI2B1, resultWrapper.AssemblyGroupMethod);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates an <see cref="ExportableAssessmentSectionAssemblyResult"/> with the assembly result
        /// based on <paramref name="assessmentSection"/>.
        /// </summary>
        /// <param name="assessmentSection">The assessment section to create an <see cref="ExportableAssessmentSectionAssemblyResult"/> for.</param>
        /// <returns>An <see cref="ExportableAssessmentSectionAssemblyResult"/> with assembly result.</returns>
        /// <exception cref="AssemblyException">Thrown when assembly result cannot be created for <paramref name="assessmentSection"/>.</exception>
        private static ExportableAssessmentSectionAssemblyResult CreateExportableAssessmentSectionAssemblyResult(AssessmentSection assessmentSection)
        {
            AssessmentSectionAssemblyResultWrapper assemblyResultWrapper = AssessmentSectionAssemblyFactory.AssembleAssessmentSection(assessmentSection);
            AssessmentSectionAssemblyResult        assemblyResult        = assemblyResultWrapper.AssemblyResult;

            return(new ExportableAssessmentSectionAssemblyResult(
                       assemblyResult.AssemblyGroup, assemblyResult.Probability,
                       ExportableAssemblyMethodFactory.Create(assemblyResultWrapper.AssemblyGroupMethod),
                       ExportableAssemblyMethodFactory.Create(assemblyResultWrapper.ProbabilityMethod)));
        }
        /// <summary>
        /// Sets the value of <paramref name="result"/> on the control.
        /// </summary>
        /// <param name="result">The <see cref="AssessmentSectionAssemblyResult"/> to set on the control.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="result"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="result"/>
        /// has an invalid value for <see cref="AssessmentSectionAssemblyGroup"/>.</exception>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="result"/>
        /// is not supported.</exception>
        public void SetAssemblyResult(AssessmentSectionAssemblyResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            groupLabel.Text      = EnumDisplayNameHelper.GetDisplayName(result.AssemblyGroup);
            groupLabel.BackColor = AssessmentSectionAssemblyGroupColorHelper.GetAssessmentSectionAssemblyGroupColor(result.AssemblyGroup);

            probabilityLabel.Text = ProbabilityFormattingHelper.FormatWithDiscreteNumbers(result.Probability);
        }
        public void Constructor_WithArguments_ExpectedValues()
        {
            // Setup
            var    random        = new Random(21);
            double probability   = random.NextDouble();
            var    assemblyGroup = random.NextEnumValue <AssessmentSectionAssemblyGroup>();

            // Call
            var result = new AssessmentSectionAssemblyResult(probability, assemblyGroup);

            // Assert
            Assert.AreEqual(probability, result.Probability);
            Assert.AreEqual(assemblyGroup, result.AssemblyGroup);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random         = new Random(21);
            var assemblyResult = new AssessmentSectionAssemblyResult(
                random.NextDouble(), random.NextEnumValue <AssessmentSectionAssemblyGroup>());
            var probabilityMethod   = random.NextEnumValue <AssemblyMethod>();
            var assemblyGroupMethod = random.NextEnumValue <AssemblyMethod>();

            // Call
            var wrapper = new AssessmentSectionAssemblyResultWrapper(assemblyResult, probabilityMethod, assemblyGroupMethod);

            // Assert
            Assert.AreSame(assemblyResult, wrapper.AssemblyResult);
            Assert.AreEqual(probabilityMethod, wrapper.ProbabilityMethod);
            Assert.AreEqual(assemblyGroupMethod, wrapper.AssemblyGroupMethod);
        }
예제 #7
0
        public void SetAssemblyResult_WithResult_SetsValues()
        {
            // Setup
            var random = new Random(39);
            var result = new AssessmentSectionAssemblyResult(random.NextDouble(),
                                                             random.NextEnumValue <AssessmentSectionAssemblyGroup>());

            using (var resultControl = new AssessmentSectionAssemblyResultControl())
            {
                // Call
                resultControl.SetAssemblyResult(result);

                // Assert
                BorderedLabel groupLabel = GetGroupLabel(resultControl);
                AssertGroupLabel(result.AssemblyGroup, groupLabel);

                BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
                AssertProbabilityLabel(result.Probability, probabilityLabel);
            }
        }