public void IsNotNull_NullableHasValue_DoesNotThrow() { int?nullable = 5; Assert.DoesNotThrow( () => ParameterValidation.IsNotNull(nullable, TestParameterName)); }
/// <summary> /// Initializes a new instance of the <see cref="Fruit"/> class with the specified quality. /// </summary> /// <param name="quality">The quality of this instance of fruit.</param> /// <exception cref="ArgumentOutOfRangeException"><para><paramref name="quality"/> is less /// than 0.</para><para>-or-</para><para><paramref name="quality"/> is greater than 100. /// </para></exception> protected Fruit(int quality) { ParameterValidation .IsBetweenInclusive(quality, MinQuality, MaxQuality, nameof(quality)); this.Quality = quality; }
public static int[] FindNumberProteinInterfacesPerChain(ClusteringFullResultListContainer proteinInterfaces, int[] detectedBestClusterStagesIndexes) { if (ParameterValidation.IsClusteringFullResultListContainerNullOrEmpty(proteinInterfaces)) { throw new ArgumentOutOfRangeException(nameof(proteinInterfaces)); } if (ParameterValidation.IsIntArrayNullOrEmpty(detectedBestClusterStagesIndexes)) { throw new ArgumentOutOfRangeException(nameof(detectedBestClusterStagesIndexes)); } int totalChains = proteinInterfaces.ChainList.Count; var result = new int[totalChains]; for (int chainIndex = 0; chainIndex < totalChains; chainIndex++) { int stageIndex = detectedBestClusterStagesIndexes[chainIndex]; if (stageIndex > -1) { int chainCalculatedProteinInterfaceCount = proteinInterfaces.ChainList[chainIndex].StageList[stageIndex].ClusterList.Count(proteinInterface => proteinInterface != null && proteinInterface.AtomIndexList != null && proteinInterface.AtomIndexList.Count > 0); result[chainIndex] = chainCalculatedProteinInterfaceCount; } else { result[chainIndex] = 0; } } return(result); }
public static decimal CalculateProteinInterfaceAverageResidueSequenceIndex(ClusteringResultProteinInterfaceListContainer.Chain.ProteinInterface proteinInterface) { if (ParameterValidation.IsProteinInterfaceNullOrEmpty(proteinInterface)) { throw new ArgumentOutOfRangeException(nameof(proteinInterface)); } decimal sumTotal = 0.0m; int sumAtoms = 0; foreach (ATOM_Record atom in proteinInterface.AtomList) { int residueSequenceIndex; if (int.TryParse(atom.resSeq.FieldValue, out residueSequenceIndex)) { sumTotal += residueSequenceIndex; sumAtoms++; } } decimal average = -1m; if (sumAtoms > 0) { average = sumTotal / sumAtoms; } return(average); }
public static ClusteringResultProteinInterfaceListContainer SortProteinInterfacesByResidueSequenceIndexAverage(ClusteringResultProteinInterfaceListContainer interactionProteinInterfaces) { if (ParameterValidation.IsClusteringResultProteinInterfaceListContainerNullOrEmpty(interactionProteinInterfaces)) { throw new ArgumentOutOfRangeException(nameof(interactionProteinInterfaces)); } bool outOfOrder = true; while (outOfOrder) { outOfOrder = false; for (int chainIndex = 0; chainIndex < interactionProteinInterfaces.ChainList.Count; chainIndex++) { for (int proteinInterfaceIndex = 1; proteinInterfaceIndex < interactionProteinInterfaces.ChainList[chainIndex].ProteinInterfaceList.Count; proteinInterfaceIndex++) { ClusteringResultProteinInterfaceListContainer.Chain.ProteinInterface proteinInterface = interactionProteinInterfaces.ChainList[chainIndex].ProteinInterfaceList[proteinInterfaceIndex]; ClusteringResultProteinInterfaceListContainer.Chain.ProteinInterface lastProteinInterface = interactionProteinInterfaces.ChainList[chainIndex].ProteinInterfaceList[proteinInterfaceIndex - 1]; decimal proteinInterfaceAverage = CalculateProteinInterfaceAverageResidueSequenceIndex(proteinInterface); decimal lastProteinInterfaceAverage = CalculateProteinInterfaceAverageResidueSequenceIndex(lastProteinInterface); if (proteinInterfaceAverage < lastProteinInterfaceAverage) { interactionProteinInterfaces.ChainList[chainIndex].ProteinInterfaceList[proteinInterfaceIndex] = lastProteinInterface; interactionProteinInterfaces.ChainList[chainIndex].ProteinInterfaceList[proteinInterfaceIndex - 1] = proteinInterface; outOfOrder = true; } } } } return(interactionProteinInterfaces); }
public static ATOM_Record FindAtomInsidePdbFileChain(ProteinChainListContainer pdbFileChains, int chainIndex, int residueSequenceIndex) { if (ParameterValidation.IsProteinChainListContainerNullOrEmpty(pdbFileChains)) { return(null); } if (ParameterValidation.IsChainIndexInvalid(chainIndex)) { throw new ArgumentOutOfRangeException(nameof(chainIndex)); } if (ParameterValidation.IsResidueSequenceIndexInvalid(residueSequenceIndex, true)) { throw new ArgumentOutOfRangeException(nameof(residueSequenceIndex)); } for (int memberIndex = 0; memberIndex < pdbFileChains.ChainList[chainIndex].AtomList.Count; memberIndex++) { ATOM_Record atom = pdbFileChains.ChainList[chainIndex].AtomList[memberIndex]; if (ProteinDataBankFileOperations.NullableTryParseInt32(atom.resSeq.FieldValue) == residueSequenceIndex) { return(atom); } } return(null); }
public void IsNotEmpty_EmptyValue_ArgumentNullException() { var ex = Assert.Throws <ArgumentException>( () => ParameterValidation.IsNotEmpty(string.Empty, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
#pragma warning disable MEN007 // Use a single return /// <summary> /// Attempts to resolve an <see cref="IArgumentConverter"/> from the specified property. /// </summary> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> that describes the property /// to resolve an <see cref="IArgumentConverter"/> from.</param> /// <returns>The resolved <see cref="IArgumentConverter"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="propertyInfo"/> is /// <see langword="null"/>.</exception> /// <exception cref="ArgumentConverterResolveException">An <see cref="IArgumentConverter"/> /// could not be resolved from <paramref name="propertyInfo"/>.</exception> public static IArgumentConverter Resolve(PropertyInfo propertyInfo) #pragma warning restore MEN007 // Use a single return { ParameterValidation.IsNotNull(propertyInfo, nameof(propertyInfo)); if (propertyInfo.PropertyType == typeof(string)) { return(new DefaultArgumentConverter()); } var typeConverter = FindTypeConverter(propertyInfo); if (typeConverter != null) { return(new TypeConverterArgumentConverter(typeConverter)); } var implicitOperator = FindImplicitOperator(propertyInfo); if (implicitOperator != null) { return(new ImplicitArgumentConverter(implicitOperator)); } throw new ArgumentConverterResolveException( propertyInfo.Name, propertyInfo.PropertyType); }
/// <summary> /// Initializes a new instance of the <see cref="EqualsOverrideAssertion"/> class. /// </summary> /// <param name="specimenBuilder">The anonymous object creation service to use to create new /// specimens.</param> /// <param name="successiveCount">The number of invocations to test on an Equals override /// for successive contract tests.</param> /// <exception cref="ArgumentNullException"><paramref name="specimenBuilder"/> is /// <see langword="null"/>.</exception> protected EqualsOverrideAssertion(ISpecimenBuilder specimenBuilder, int successiveCount) { ParameterValidation.IsNotNull(specimenBuilder, nameof(specimenBuilder)); this.SpecimenBuilder = specimenBuilder; this.SuccessiveCount = successiveCount; }
public CustomSettingsProvider(IExternalFileConfigurationProvider externalFileProvider, IWebConfigProvider webConfigProvider) { ParameterValidation.IsNotNull(externalFileProvider, nameof(externalFileProvider)); ParameterValidation.IsNotNull(webConfigProvider, nameof(webConfigProvider)); this.externalFileProvider = externalFileProvider; this.webConfigProvider = webConfigProvider; this.externalConfiguration = new Lazy <Configuration>(() => { Configuration settings = this.externalFileProvider.GetSettings(); return(settings); }); this.webConfigSettings = new Lazy <CustomSettingsConfigSection>(() => { CustomSettingsConfigSection settings = this.webConfigProvider.GetCustomSettings(); return(settings); }); this.appSettings = new Lazy <IDictionary <string, string> >(() => { IDictionary <string, string> settings = this.webConfigProvider.GetAppSettings(); return(settings); }); }
/// <inheritdoc/> void ISortStrategy <T> .Sort(IList <T> list, IComparer <T> comparer) { ParameterValidation.IsNotNull(list, nameof(list)); ParameterValidation.IsNotNull(comparer, nameof(comparer)); this.Sort(list, comparer); }
/// <summary> /// Initialises a new instance of the <see cref="Path"/> class. /// </summary> /// <param name="inCell0">The in cell1.</param> /// <param name="inCell1">The in cell2.</param> /// <param name="inCell2">The in cell3.</param> internal Path(Cell inCell0, Cell inCell1, Cell inCell2) { ParameterValidation.EnsureNotNull(inCell0, "inCell0"); ParameterValidation.EnsureNotNull(inCell1, "inCell1"); ParameterValidation.EnsureNotNull(inCell2, "inCell2"); if (inCell0 == inCell1) { ThrowDuplicateCellException("inCell0", "inCell1"); } if (inCell1 == inCell2) { ThrowDuplicateCellException("inCell1", "inCell2"); } if (inCell0 == inCell2) { ThrowDuplicateCellException("inCell0", "inCell2"); } // Record the cells in the path. myCells[0] = inCell0; myCells[1] = inCell1; myCells[2] = inCell2; // Register an event handler for when any Cell in the Path changes. foreach (Cell aCell in myCells) { aCell.StateChanged += Path_CellStateChanged; } }
public void Verify(IGuardClauseCommand command) { ParameterValidation.IsNotNull(command, nameof(command)); if (command.RequestedType.IsClass || command.RequestedType.IsInterface) { var newCommand = this.guardClauseExtensions.CreateExtendedCommand(this.specimenBuilder, command); var expectedExceptionThrown = false; try { newCommand.Execute(null); } catch (ArgumentNullException) { expectedExceptionThrown = true; } catch (Exception ex) { throw newCommand.CreateException("null", ex); } if (!expectedExceptionThrown) { throw newCommand.CreateException("null"); } } }
void gridParam_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex != colGroupNo.Index && e.ColumnIndex != colCount.Index) { return; } string value = e.FormattedValue.ToString(); if (value == string.Empty) { return; } //check if group and count are non-negative integers (exception: DefIL allows for decimals for parameters + and -) string errorText = string.Empty; string parameterName = e.ColumnIndex == colCount.Index ? string.Empty : dgvParameter.Rows[e.RowIndex].Cells[colParameter.Index].Value.ToString(); if (!ParameterValidation.ValidateGroupInput(value, parameterName, ref errorText)) { Tools.UserInfoHandler.ShowError(errorText); e.Cancel = true; } else { if (dgvParameter.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue != e.FormattedValue) { dgvParameter.Rows[e.RowIndex].Cells[colAdd.Index].Value = true; //automatically select param if group or count is changed } } }
/// <summary> /// Initializes a new instance of the <see cref="ParameterAttribute"/> class. /// </summary> /// <param name="parameterName">The name of the parameter to apply a known value to.</param> /// <exception cref="ArgumentNullException"><paramref name="parameterName"/> is /// <see langword="null"/>.</exception> /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty. /// </exception> public ParameterAttribute(string parameterName) { ParameterValidation.IsNotNull(parameterName, nameof(parameterName)); ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName)); this.ParameterName = parameterName; }
/// <summary> /// This method finds the smallest value in the given distance array. If the smallest value appears more than once, /// then the lower index is returned. /// </summary> /// <param name="distances">The pre-calculated distance matrix.</param> /// <returns>The first smallest distance index.</returns> public static int[] FirstSmallestDistanceIndex(decimal[,] distances) { if (ParameterValidation.IsDecimalArrayNullOrEmpty(distances)) { return(null); } var indexSmallest = new[] { 0, 0 }; //var indexSmallestA = 0; //var indexSmallestB = 0; for (int indexA = distances.GetLowerBound(0); indexA <= distances.GetUpperBound(0); indexA++) { for (int indexB = distances.GetLowerBound(1); indexB <= distances.GetUpperBound(1); indexB++) { if ((indexA != indexB) && ((indexSmallest[0] == indexSmallest[1]) || (Math.Abs(distances[indexA, indexB]) < Math.Abs(distances[indexSmallest[0], indexSmallest[1]])))) { indexSmallest[0] = indexA; indexSmallest[1] = indexB; } } } return(indexSmallest); // new int[] { indexSmallestA, indexSmallestB }; }
/// <summary> /// Gets the full name of the type, including any generic type parameters. /// </summary> /// <typeparam name="T">The type of the instance (will be inferred).</typeparam> /// <param name="inInstance">The instance for which to get the type name.</param> /// <returns>The full name of the type, including any generic type parameters.</returns> public static string GetGenericAwareFullTypeName <T>(this T inInstance) { ParameterValidation.EnsureNotNull(inInstance, "inInstance"); Type theType = typeof(T); return(theType.GetGenericAwareTypeName(theType.FullName)); }
public static ATOM_Record FindAtomInsideSingularInteractionsChain(ProteinChainListContainer singularAaToAaInteractions, int chainIndex, int residueSequenceIndex) { if (ParameterValidation.IsProteinChainListContainerNullOrEmpty(singularAaToAaInteractions)) { return(null); } if (ParameterValidation.IsChainIndexInvalid(chainIndex)) { throw new ArgumentOutOfRangeException(nameof(chainIndex)); } if (ParameterValidation.IsResidueSequenceIndexInvalid(residueSequenceIndex, true)) { throw new ArgumentOutOfRangeException(nameof(residueSequenceIndex)); } // Loop through atoms in specified chain to find atom with given residue sequence index for (int atomIndex = 0; atomIndex < singularAaToAaInteractions.ChainList[chainIndex].AtomList.Count; atomIndex++) { ATOM_Record atom = singularAaToAaInteractions.ChainList[chainIndex].AtomList[atomIndex]; if (ProteinDataBankFileOperations.NullableTryParseInt32(atom.resSeq.FieldValue) == residueSequenceIndex) { return(atom); } } return(null); }
public void IsNotNull_NullValue_ArgumentNullException() { var ex = Assert.Throws <ArgumentNullException>( () => ParameterValidation.IsNotNull((string)null, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
public void IsFalse_TrueValue_ArgumentException() { var ex = Assert.Throws <ArgumentException>( () => ParameterValidation.IsFalse(true, "Message", TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
public void IsLessThan_OutOfRangeValue_ArgumentOutOfRangeException( [Values(0, 1, int.MaxValue)] int value) { var ex = Assert.Throws <ArgumentOutOfRangeException>( () => ParameterValidation.IsLessThan(value, 0, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
/// <summary> /// Initializes a new instance of the <see cref="ParsedCommand"/> class. /// </summary> /// <param name="name">The name of the command described by this /// <see cref="ParsedCommand"/>.</param> /// <param name="arguments">The arguments of the command described by this /// <see cref="ParsedCommand"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="name"/>, or /// <paramref name="arguments"/> is <see langword="null"/>.</exception> public ParsedCommand(string name, IEnumerable <string> arguments) { ParameterValidation.IsNotNull(name, nameof(name)); ParameterValidation.IsNotNull(arguments, nameof(arguments)); this.Name = name; this.Arguments = new ReadOnlyCollection <string>(arguments.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="PagingCriterion{TEntity}" /> class. /// </summary> /// <param name="skipCount">The number of entities to skip when this /// <see cref="PagingCriterion{TEntity}"/> is applied.</param> /// <param name="pageSize">The number of entities to take when this /// <see cref="PagingCriterion{TEntity}"/> is applied.</param> /// <exception cref="ArgumentOutOfRangeException"><para><paramref name="skipCount"/> is less /// then 0.</para><para>-or-</para><para><paramref name="pageSize"/> is less than 1.</para> /// </exception> public PagingCriterion(int skipCount, int pageSize) { ParameterValidation.IsGreaterThanOrEqualTo(skipCount, 0, nameof(skipCount)); ParameterValidation.IsGreaterThan(pageSize, 0, nameof(pageSize)); this.SkipCount = skipCount; this.PageSize = pageSize; }
public void IsBetweenInclusive_OutOfRangeValue_ArgumentOutOfRangeException( [Values(-11, -12, int.MinValue, 11, 12, int.MaxValue)] int value) { var ex = Assert.Throws <ArgumentOutOfRangeException>( () => ParameterValidation.IsBetweenInclusive(value, -10, 10, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
public void IsGreaterThanOrEqualTo_OutOfRangeValue_ArgumentOutOfRangeException( [Values(-1, -2, int.MinValue)] int value) { var ex = Assert.Throws <ArgumentOutOfRangeException>( () => ParameterValidation.IsGreaterThanOrEqualTo(value, 0, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
public void IsNotNull_NullableNoValue_ArgumentNullException() { int?nullable = null; var ex = Assert.Throws <ArgumentNullException>( () => ParameterValidation.IsNotNull(nullable, TestParameterName)); Assert.That(ex.ParamName, Is.EqualTo(TestParameterName)); }
/// <summary> /// Initializes a new instance of the <see cref="ExampleListCommand"/> class. /// </summary> /// <param name="exampleMetadataCollectionFactory">The /// <see cref="ExampleMetadataCollectionFactory"/> to use to create a collection of /// instances of <see cref="ExampleMetadata"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="exampleMetadataCollectionFactory"/> is <see langword="null"/>. /// </exception> public ExampleListCommand(ExampleMetadataCollectionFactory exampleMetadataCollectionFactory) { ParameterValidation.IsNotNull( exampleMetadataCollectionFactory, nameof(exampleMetadataCollectionFactory)); this.exampleMetadataCollectionFactory = exampleMetadataCollectionFactory; }
/// <summary> /// Determines whether the specified <see cref="MethodInfo"/> represents an Equals method /// implementation with a parameter type of <see cref="object"/>. /// </summary> /// <param name="methodInfo">The <see cref="MethodInfo"/> to check.</param> /// <returns> /// <see langword="true"/> if the specified <see cref="MethodInfo"/> is an Equals method /// with a parameter type of <see cref="object"/>; otherwise, <see langword="false"/>. /// </returns> protected static bool IsEqualsParameterObjectType(MethodInfo methodInfo) { ParameterValidation.IsNotNull(methodInfo, nameof(methodInfo)); var parameterType = methodInfo.GetParameters().First().ParameterType; return(parameterType == typeof(object)); }
public static List <ATOM_Record> FindAtomInteractingWithOtherProteinInterfaces(ATOM_Record atom, InteractionBetweenProteinInterfacesListContainer interactionBetweenProteinInterfacesContainer, FindAtomInteractingWithAnotherProteinInterfaceOptions findAtomInteractingWithAnotherProteinInterfaceOptions) { if (ParameterValidation.IsAtomNullOrEmpty(atom)) { throw new ArgumentNullException(nameof(atom)); } if (ParameterValidation.IsInteractionBetweenProteinInterfacesListContainerNullOrEmpty(interactionBetweenProteinInterfacesContainer)) { ////////Console.WriteLine("empty"); return(null); } List <InteractionBetweenProteinInterfaces> searchList = null; if (findAtomInteractingWithAnotherProteinInterfaceOptions == FindAtomInteractingWithAnotherProteinInterfaceOptions.FindAtomsInteractingWithOtherProteinInterfaces) { searchList = interactionBetweenProteinInterfacesContainer.InteractionBetweenProteinInterfacesList; } else if (findAtomInteractingWithAnotherProteinInterfaceOptions == FindAtomInteractingWithAnotherProteinInterfaceOptions.FindAtomsInteractingWithNonProteinInterfaces) { searchList = interactionBetweenProteinInterfacesContainer.InteractionBetweenNonProteinInterfacesList; } else { throw new NotImplementedException(); } if (searchList == null) { ////////Console.WriteLine("returning null"); return(null); } var result = new List <ATOM_Record>(); foreach (InteractionBetweenProteinInterfaces interaction in searchList) { if (interaction.Atom1.Atom == atom && interaction.Atom2.Atom != atom) { //return interaction.Atom1.Atom; result.Add(interaction.Atom2.Atom); } if (interaction.Atom1.Atom != atom && interaction.Atom2.Atom == atom) { //return interaction.Atom2.Atom; result.Add(interaction.Atom1.Atom); } } //if (result.Count == 0) //{ // //////Console.WriteLine("returning empty list"); //} return(result); }
public static Point1D AtomResidueSequencePoint1D(ATOM_Record atom) { if (ParameterValidation.IsAtomNullOrEmpty(atom)) { throw new ArgumentOutOfRangeException(nameof(atom)); } return(new Point1D(atom.resSeq.FieldValue)); }