public void RandomShuffle_AfterShuffle_ContainsAllElements() { var list = Enumerable.Range(0, 20).ToList(); var shuffled = Enumerable.Range(0, 20).ToList(); shuffled.RandomShuffle(new Random(0x12345678)); ListAssert.ContainsSameItems(list, shuffled); }
public void GetCategoricalEntailmentEnsembleClassifierTest() { // state is null { string parameterName = "state"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: null, featureVariables: testableContext.FeatureVariables, responseVariable: testableContext.ResponseVariable); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: parameterName); } // state has wrong count { string STR_EXCEPT_CEE_INVALID_STATE_COUNT = ImplementationServices.GetResourceString( "STR_EXCEPT_CEE_INVALID_STATE_COUNT"); string parameterName = "state"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 8), featureVariables: testableContext.FeatureVariables, responseVariable: testableContext.ResponseVariable); }, expectedType: typeof(ArgumentException), expectedPartialMessage: STR_EXCEPT_CEE_INVALID_STATE_COUNT, expectedParameterName: parameterName); } // featureVariables is null { string parameterName = "featureVariables"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, 1.0 }), featureVariables: null, responseVariable: testableContext.ResponseVariable); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: parameterName); } // featureVariables has wrong count { string STR_EXCEPT_CEE_MUST_HAVE_SAME_FEATURES_COUNT = ImplementationServices.GetResourceString( "STR_EXCEPT_CEE_MUST_HAVE_SAME_FEATURES_COUNT"); string parameterName = "featureVariables"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, 1.0 }), featureVariables: new List <CategoricalVariable>(), responseVariable: testableContext.ResponseVariable); }, expectedType: typeof(ArgumentException), expectedPartialMessage: STR_EXCEPT_CEE_MUST_HAVE_SAME_FEATURES_COUNT, expectedParameterName: parameterName); } // featureVariables contains a variable having wrong number of categories { string STR_EXCEPT_CEE_INVALID_FEATURE_CATEGORIES_COUNT = ImplementationServices.GetResourceString( "STR_EXCEPT_CEE_INVALID_FEATURE_CATEGORIES_COUNT"); string parameterName = "featureVariables"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, 1.0 }), featureVariables: new List <CategoricalVariable>() { new CategoricalVariable("F") { { 0.0, "A" }, 1.0 } }, responseVariable: testableContext.ResponseVariable); }, expectedType: typeof(ArgumentException), expectedPartialMessage: STR_EXCEPT_CEE_INVALID_FEATURE_CATEGORIES_COUNT, expectedParameterName: parameterName); } // responseVariable is null { string parameterName = "responseVariable"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, 1.0 }), featureVariables: testableContext.FeatureVariables, responseVariable: null); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: parameterName); } // responseVariable has a wrong number of categories { string STR_EXCEPT_CEE_INVALID_RESPONSE_CATEGORIES_COUNT = ImplementationServices.GetResourceString( "STR_EXCEPT_CEE_INVALID_RESPONSE_CATEGORIES_COUNT"); string parameterName = "responseVariable"; var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; ArgumentExceptionAssert.Throw( () => { context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, 1.0 }), featureVariables: testableContext.FeatureVariables, responseVariable: new CategoricalVariable("R") { { 0.0, "A" } }); }, expectedType: typeof(ArgumentException), expectedPartialMessage: STR_EXCEPT_CEE_INVALID_RESPONSE_CATEGORIES_COUNT, expectedParameterName: parameterName); } // valid input { var testableContext = TestableCategoricalEntailmentEnsembleOptimizationContext01.Get(); var context = testableContext.Context; var actual = context.GetCategoricalEntailmentEnsembleClassifier( state: DoubleMatrix.Dense(1, 9, new double[9] { 0, 0, 0, 1, 1, 1, 1, 0, .99 }), featureVariables: testableContext.FeatureVariables, responseVariable: testableContext.ResponseVariable); var expected = new CategoricalEntailmentEnsembleClassifier( featureVariables: testableContext.FeatureVariables, responseVariable: testableContext.ResponseVariable); expected.Add( new CategoricalEntailment( featureVariables: testableContext.FeatureVariables, responseVariable: testableContext.ResponseVariable, featurePremises: new List <SortedSet <double> >() { new SortedSet <double>() { 3.0, 4.0, 5.0 } }, responseConclusion: 0.0, truthValue: .99)); ListAssert <CategoricalEntailment> .ContainSameItems( expected : new List <CategoricalEntailment>(expected.Entailments), actual : new List <CategoricalEntailment>(actual.Entailments), areEqual : CategoricalEntailmentAssert.AreEqual); } }