github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/power/power_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package power
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestPower(t *testing.T) {
    24  	//Test values
    25  	lvs := []float64{2, 3, 4, 5, 6, 7, 8, 9}
    26  	rvs := []float64{2, 2, 3, 3, 4, 4, 2, 2}
    27  
    28  	//Predefined Correct Values
    29  	expected := []float64{4, 9, 64, 125, 1296, 2401, 64, 81}
    30  
    31  	newNums := Power(lvs, rvs, rvs)
    32  
    33  	for i := range newNums {
    34  		require.Equal(t, expected[i], newNums[i])
    35  	}
    36  }
    37  
    38  func TestPowerScalarLeftConst(t *testing.T) {
    39  	//Test values
    40  	var lc float64 = 2
    41  	rvs := []float64{2, 3, 4, 5, 6, 7, 8, 9}
    42  
    43  	//Predefined Correct Values
    44  	expected := []float64{4, 8, 16, 32, 64, 128, 256, 512}
    45  
    46  	newNums := PowerScalarLeftConst(lc, rvs, rvs)
    47  
    48  	for i := range newNums {
    49  		require.Equal(t, expected[i], newNums[i])
    50  	}
    51  }
    52  
    53  func TestPowerScalarRightConst(t *testing.T) {
    54  	//Test values
    55  	lvs := []float64{2, 3, 4, 5, 6, 7, 8, 9}
    56  	var rc float64 = 2
    57  
    58  	//Predefined Correct Values
    59  	expected := []float64{4, 9, 16, 25, 36, 49, 64, 81}
    60  
    61  	newNums := PowerScalarRightConst(rc, lvs, lvs)
    62  
    63  	for i := range newNums {
    64  		require.Equal(t, expected[i], newNums[i])
    65  	}
    66  }