github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/ascii/ascii_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 ascii
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/container/nulls"
    19  	"github.com/stretchr/testify/require"
    20  	"testing"
    21  )
    22  
    23  func TestIntBatch(t *testing.T) {
    24  	xs := []int64{0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, -1, -9, -10, -99}
    25  	want := []uint8{'0', '1', '9', '1', '9', '1', '9', '1', '9', '1', '-', '-', '-', '-'}
    26  	got := make([]uint8, len(xs))
    27  	nsp := nulls.NewWithSize(len(xs))
    28  	nsp.Set(10)
    29  	IntBatch(xs, 0, got, nsp)
    30  
    31  	require.Equal(t, want[:10], got[:10])
    32  	require.Equal(t, want[11:], got[11:])
    33  }
    34  
    35  func TestUintBatch(t *testing.T) {
    36  	xs := []uint64{0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 1, 23454322345543, 987654323456789}
    37  	want := []uint8{'0', '1', '9', '1', '9', '1', '9', '1', '9', '1', '1', '2', '9'}
    38  	got := make([]uint8, len(xs))
    39  	nsp := nulls.NewWithSize(len(xs))
    40  	nsp.Set(10)
    41  	UintBatch(xs, 0, got, nsp)
    42  	require.Equal(t, want[:10], got[:10])
    43  	require.Equal(t, want[11:], got[11:])
    44  }
    45  
    46  func TestStringBatch(t *testing.T) {
    47  	xs := [][]byte{
    48  		[]byte(""),
    49  		[]byte("0"),
    50  		[]byte("1"),
    51  		[]byte("9"),
    52  		[]byte("10"),
    53  		[]byte("99"),
    54  		[]byte("100"),
    55  		[]byte("999"),
    56  		[]byte("1000"),
    57  		[]byte("9999"),
    58  		[]byte("10000"),
    59  		[]byte("-1"),
    60  		[]byte("-9"),
    61  		[]byte("-10"),
    62  		[]byte("-99"),
    63  		[]byte("45654345678908765.123456789"),
    64  	}
    65  	want := []uint8{0, '0', '1', '9', '1', '9', '1', '9', '1', '9', '1', '-', '-', '-', '-', '4'}
    66  	got := make([]uint8, len(xs))
    67  	nsp := nulls.NewWithSize(len(xs))
    68  	nsp.Set(10)
    69  	StringBatch(xs, got, nsp)
    70  
    71  	require.Equal(t, want[:10], got[:10])
    72  	require.Equal(t, want[11:], got[11:])
    73  }