diff --git a/pkg/model/estimator/local/xgboost_model_weight_test.go b/pkg/model/estimator/local/xgboost_model_weight_test.go new file mode 100644 index 0000000000..d83fb8c4ef --- /dev/null +++ b/pkg/model/estimator/local/xgboost_model_weight_test.go @@ -0,0 +1,54 @@ +/* +Copyright 2023. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package local + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("XGBoostModelWeight", func() { + var ( + model XGBoostModelWeight + usageMetricNames []string + usageMetricValues [][]float64 + systemMetaDataFeatureNames []string + systemMetaDataFeatureValues []string + expectedOutput, output []float64 + ) + + BeforeEach(func() { + model = XGBoostModelWeight{} + usageMetricNames = []string{"metric1", "metric2", "metric3"} + usageMetricValues = [][]float64{{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}} + systemMetaDataFeatureNames = []string{"feature1", "feature2"} + systemMetaDataFeatureValues = []string{"value1", "value2"} + expectedOutput = []float64{1.0, 2.0} + }) + + It("should return the expected output", func() { + output = model.predict(usageMetricNames, usageMetricValues, systemMetaDataFeatureNames, systemMetaDataFeatureValues) + Expect(output).To(Equal(expectedOutput)) + }) + + It("should panic when the number of features in the model and usageMetricValues are not equal", func() { + usageMetricValues = [][]float64{{1.0, 2.0}, {4.0, 5.0}} + Expect(func() { + model.predict(usageMetricNames, usageMetricValues, systemMetaDataFeatureNames, systemMetaDataFeatureValues) + }).To(Panic()) + }) +})