github.com/parquet-go/parquet-go@v0.20.0/page_min_test.go (about)

     1  package parquet
     2  
     3  import (
     4  	"bytes"
     5  	"math/rand"
     6  	"testing"
     7  
     8  	"github.com/parquet-go/parquet-go/internal/quick"
     9  )
    10  
    11  func TestMinInt32(t *testing.T) {
    12  	err := quick.Check(func(values []int32) bool {
    13  		min := int32(0)
    14  		if len(values) > 0 {
    15  			min = values[0]
    16  			for _, v := range values[1:] {
    17  				if v < min {
    18  					min = v
    19  				}
    20  			}
    21  		}
    22  		return min == minInt32(values)
    23  	})
    24  	if err != nil {
    25  		t.Error(err)
    26  	}
    27  }
    28  
    29  func TestMinInt64(t *testing.T) {
    30  	err := quick.Check(func(values []int64) bool {
    31  		min := int64(0)
    32  		if len(values) > 0 {
    33  			min = values[0]
    34  			for _, v := range values[1:] {
    35  				if v < min {
    36  					min = v
    37  				}
    38  			}
    39  		}
    40  		return min == minInt64(values)
    41  	})
    42  	if err != nil {
    43  		t.Error(err)
    44  	}
    45  }
    46  
    47  func TestMinUint32(t *testing.T) {
    48  	err := quick.Check(func(values []uint32) bool {
    49  		min := uint32(0)
    50  		if len(values) > 0 {
    51  			min = values[0]
    52  			for _, v := range values[1:] {
    53  				if v < min {
    54  					min = v
    55  				}
    56  			}
    57  		}
    58  		return min == minUint32(values)
    59  	})
    60  	if err != nil {
    61  		t.Error(err)
    62  	}
    63  }
    64  
    65  func TestMinUint64(t *testing.T) {
    66  	err := quick.Check(func(values []uint64) bool {
    67  		min := uint64(0)
    68  		if len(values) > 0 {
    69  			min = values[0]
    70  			for _, v := range values[1:] {
    71  				if v < min {
    72  					min = v
    73  				}
    74  			}
    75  		}
    76  		return min == minUint64(values)
    77  	})
    78  	if err != nil {
    79  		t.Error(err)
    80  	}
    81  }
    82  
    83  func TestMinFloat32(t *testing.T) {
    84  	err := quick.Check(func(values []float32) bool {
    85  		min := float32(0)
    86  		if len(values) > 0 {
    87  			min = values[0]
    88  			for _, v := range values[1:] {
    89  				if v < min {
    90  					min = v
    91  				}
    92  			}
    93  		}
    94  		return min == minFloat32(values)
    95  	})
    96  	if err != nil {
    97  		t.Error(err)
    98  	}
    99  }
   100  
   101  func TestMinFloat64(t *testing.T) {
   102  	err := quick.Check(func(values []float64) bool {
   103  		min := float64(0)
   104  		if len(values) > 0 {
   105  			min = values[0]
   106  			for _, v := range values[1:] {
   107  				if v < min {
   108  					min = v
   109  				}
   110  			}
   111  		}
   112  		return min == minFloat64(values)
   113  	})
   114  	if err != nil {
   115  		t.Error(err)
   116  	}
   117  }
   118  
   119  func TestMinBE128(t *testing.T) {
   120  	err := quick.Check(func(values [][16]byte) bool {
   121  		min := [16]byte{}
   122  		if len(values) > 0 {
   123  			min = values[0]
   124  			for _, v := range values[1:] {
   125  				if bytes.Compare(v[:], min[:]) < 0 {
   126  					min = v
   127  				}
   128  			}
   129  		}
   130  		ret := minBE128(values)
   131  		return (len(values) == 0 && ret == nil) || bytes.Equal(min[:], ret)
   132  	})
   133  	if err != nil {
   134  		t.Error(err)
   135  	}
   136  }
   137  
   138  func TestMinFixedLenByteArray(t *testing.T) {
   139  	err := quick.Check(func(values []byte) bool {
   140  		min := [1]byte{}
   141  		if len(values) > 0 {
   142  			min[0] = values[0]
   143  			for _, v := range values[1:] {
   144  				if v < min[0] {
   145  					min[0] = v
   146  				}
   147  			}
   148  		}
   149  		ret := minFixedLenByteArray(values, 1)
   150  		return (len(values) == 0 && ret == nil) || bytes.Equal(min[:], ret)
   151  	})
   152  	if err != nil {
   153  		t.Error(err)
   154  	}
   155  }
   156  
   157  func BenchmarkMinInt32(b *testing.B) {
   158  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   159  		values := make([]int32, bufferSize/4)
   160  		prng := rand.New(rand.NewSource(1))
   161  		for i := range values {
   162  			values[i] = prng.Int31()
   163  		}
   164  		for i := 0; i < b.N; i++ {
   165  			minInt32(values)
   166  		}
   167  	})
   168  }
   169  
   170  func BenchmarkMinInt64(b *testing.B) {
   171  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   172  		values := make([]int64, bufferSize/8)
   173  		prng := rand.New(rand.NewSource(1))
   174  		for i := range values {
   175  			values[i] = prng.Int63()
   176  		}
   177  		for i := 0; i < b.N; i++ {
   178  			minInt64(values)
   179  		}
   180  	})
   181  }
   182  
   183  func BenchmarkMinUint32(b *testing.B) {
   184  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   185  		values := make([]uint32, bufferSize/4)
   186  		prng := rand.New(rand.NewSource(1))
   187  		for i := range values {
   188  			values[i] = prng.Uint32()
   189  		}
   190  		for i := 0; i < b.N; i++ {
   191  			minUint32(values)
   192  		}
   193  	})
   194  }
   195  
   196  func BenchmarkMinUint64(b *testing.B) {
   197  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   198  		values := make([]uint64, bufferSize/8)
   199  		prng := rand.New(rand.NewSource(1))
   200  		for i := range values {
   201  			values[i] = prng.Uint64()
   202  		}
   203  		for i := 0; i < b.N; i++ {
   204  			minUint64(values)
   205  		}
   206  	})
   207  }
   208  
   209  func BenchmarkMinFloat32(b *testing.B) {
   210  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   211  		values := make([]float32, bufferSize/4)
   212  		prng := rand.New(rand.NewSource(1))
   213  		for i := range values {
   214  			values[i] = prng.Float32()
   215  		}
   216  		for i := 0; i < b.N; i++ {
   217  			minFloat32(values)
   218  		}
   219  	})
   220  }
   221  
   222  func BenchmarkMinFloat64(b *testing.B) {
   223  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   224  		values := make([]float64, bufferSize/8)
   225  		prng := rand.New(rand.NewSource(1))
   226  		for i := range values {
   227  			values[i] = prng.Float64()
   228  		}
   229  		for i := 0; i < b.N; i++ {
   230  			minFloat64(values)
   231  		}
   232  	})
   233  }
   234  
   235  func BenchmarkMinBE128(b *testing.B) {
   236  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   237  		values := make([][16]byte, bufferSize)
   238  		prng := rand.New(rand.NewSource(1))
   239  		for i := range values {
   240  			prng.Read(values[i][:])
   241  		}
   242  		for i := 0; i < b.N; i++ {
   243  			minBE128(values)
   244  		}
   245  	})
   246  }
   247  
   248  func BenchmarkMinFixedLenByteArray(b *testing.B) {
   249  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
   250  		values := make([]byte, bufferSize)
   251  		prng := rand.New(rand.NewSource(1))
   252  		prng.Read(values)
   253  		for i := 0; i < b.N; i++ {
   254  			minFixedLenByteArray(values, 32)
   255  		}
   256  	})
   257  }