public void AverageLinkageTest() { // left is null { ArgumentExceptionAssert.Throw( () => { Distance.AverageLinkage( left: (DoubleMatrix)null, right: DoubleMatrix.Identity(2)); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: "left"); } // right is null { ArgumentExceptionAssert.Throw( () => { Distance.AverageLinkage( left: DoubleMatrix.Identity(2), right: (DoubleMatrix)null); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: "right"); } // right and left have not the same number of columns { ArgumentExceptionAssert.Throw( () => { Distance.AverageLinkage( left: DoubleMatrix.Identity(2), right: DoubleMatrix.Identity(3)); }, expectedType: typeof(ArgumentException), expectedPartialMessage: string.Format( ImplementationServices.GetResourceString( "STR_EXCEPT_PAR_MUST_HAVE_SAME_NUM_OF_COLUMNS"), "left"), expectedParameterName: "right"); } // input is valid { var items = IndexCollection.Range(0, 3); int numberOfItems = items.Count; var attributes = IrisDataSet.GetAttributesAsDoubleMatrix(); var classes = IrisDataSet.GetClasses(); var partition = IndexPartition.Create(classes); var left = attributes[partition["virginica"], ":"][items, ":"]; var right = attributes[partition["setosa"], ":"][items, ":"]; var actual = Distance.AverageLinkage(left, right); var expected = 4.932325; Assert.AreEqual(expected, actual, DoubleMatrixTest.Accuracy); } }