public void AssembleAssessmentSection_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException() { // 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; kernel.AssemblyProbability = new Probability(random.NextDouble()); kernel.AssemblyGroup = (EAssessmentGrade)99; var calculator = new AssessmentSectionAssemblyCalculator(factory); // Call void Call() => calculator.AssembleAssessmentSection(Enumerable.Empty <double>(), maximumAllowableFloodingProbability, signalFloodingProbability); // Assert var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call); Assert.IsInstanceOf <InvalidEnumArgumentException>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
public void AssembleAssessmentSection_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException() { // 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; kernel.ThrowAssemblyExceptionOnCalculate = true; var calculator = new AssessmentSectionAssemblyCalculator(factory); // Call void Call() => calculator.AssembleAssessmentSection(Enumerable.Empty <double>(), maximumAllowableFloodingProbability, signalFloodingProbability); // Assert var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call); Assert.IsInstanceOf <AssemblyException>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[] { AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.InvalidCategoryLimits) }), exception.Message); } }
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); } }
public void AssembleAssessmentSection_WithValidInput_InputCorrectlySetToKernel() { // Setup var random = new Random(21); double signalFloodingProbability = random.NextDouble(); double maximumAllowableFloodingProbability = signalFloodingProbability + 1e-3; int nrOfProbabilities = random.Next(1, 10); IEnumerable <double> failureMechanismProbabilities = Enumerable.Repeat(random.NextDouble(), nrOfProbabilities) .ToArray(); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; var assessmentSectionCategories = new CategoriesList <AssessmentSectionCategory>(new[] { new AssessmentSectionCategory(random.NextEnumValue <EAssessmentGrade>(), new Probability(0), new Probability(1)) }); AssemblyCategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedAssemblyCategoryLimitsKernel; categoryLimitsKernel.AssessmentSectionCategoryLimits = assessmentSectionCategories; AssessmentSectionAssemblyKernelStub assessmentSectionAssemblyKernel = factory.LastCreatedAssessmentSectionAssemblyKernel; var assemblyProbability = new Probability(random.NextDouble()); assessmentSectionAssemblyKernel.AssemblyProbability = assemblyProbability; assessmentSectionAssemblyKernel.AssemblyGroup = random.NextEnumValue <EAssessmentGrade>(); var calculator = new AssessmentSectionAssemblyCalculator(factory); // Call calculator.AssembleAssessmentSection(failureMechanismProbabilities, maximumAllowableFloodingProbability, signalFloodingProbability); // Assert Assert.IsTrue(categoryLimitsKernel.Calculated); ProbabilityAssert.AreEqual(maximumAllowableFloodingProbability, categoryLimitsKernel.AssessmentSection.MaximumAllowableFloodingProbability); ProbabilityAssert.AreEqual(signalFloodingProbability, categoryLimitsKernel.AssessmentSection.SignalFloodingProbability); Assert.IsTrue(assessmentSectionAssemblyKernel.ProbabilityCalculated); Assert.IsTrue(assessmentSectionAssemblyKernel.AssemblyGroupCalculated); Assert.IsFalse(assessmentSectionAssemblyKernel.PartialAssembly); Assert.AreSame(assessmentSectionCategories, assessmentSectionAssemblyKernel.Categories); IEnumerable <Probability> actualProbabilitiesInput = assessmentSectionAssemblyKernel.FailureMechanismProbabilities; Assert.AreEqual(nrOfProbabilities, actualProbabilitiesInput.Count()); for (var i = 0; i < nrOfProbabilities; i++) { ProbabilityAssert.AreEqual(failureMechanismProbabilities.ElementAt(i), actualProbabilitiesInput.ElementAt(i)); } Assert.AreEqual(assemblyProbability, assessmentSectionAssemblyKernel.AssemblyProbabilityInput); } }
public void AssembleAssessmentSection_FailureMechanismProbabilitiesNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var kernelFactory = mocks.Stub <IAssemblyToolKernelFactory>(); mocks.ReplayAll(); var random = new Random(21); var calculator = new AssessmentSectionAssemblyCalculator(kernelFactory); // Call void Call() => calculator.AssembleAssessmentSection(null, random.NextDouble(), random.NextDouble()); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanismProbabilities", exception.ParamName); }