Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Huamin Chen <[email protected]>
  • Loading branch information
rootfs committed Nov 13, 2023
1 parent 461685b commit 6900b52
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/model/estimator/local/xgboost_model_weight_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})

0 comments on commit 6900b52

Please sign in to comment.