github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/deprecated/int96_test.go (about)

     1  package deprecated_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/segmentio/parquet-go/deprecated"
     8  )
     9  
    10  func TestInt96Less(t *testing.T) {
    11  	tests := []struct {
    12  		i    deprecated.Int96
    13  		j    deprecated.Int96
    14  		less bool
    15  	}{
    16  		{
    17  			i:    deprecated.Int96{},
    18  			j:    deprecated.Int96{},
    19  			less: false,
    20  		},
    21  
    22  		{
    23  			i:    deprecated.Int96{0: 1},
    24  			j:    deprecated.Int96{0: 2},
    25  			less: true,
    26  		},
    27  
    28  		{
    29  			i:    deprecated.Int96{0: 1},
    30  			j:    deprecated.Int96{1: 1},
    31  			less: true,
    32  		},
    33  
    34  		{
    35  			i:    deprecated.Int96{0: 1},
    36  			j:    deprecated.Int96{2: 1},
    37  			less: true,
    38  		},
    39  
    40  		{
    41  			i:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    42  			j:    deprecated.Int96{},                                            // 0
    43  			less: true,
    44  		},
    45  
    46  		{
    47  			i:    deprecated.Int96{},                                            // 0
    48  			j:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    49  			less: false,
    50  		},
    51  
    52  		{
    53  			i:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    54  			j:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    55  			less: false,
    56  		},
    57  
    58  		{
    59  			i:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    60  			j:    deprecated.Int96{0: 0xFFFFFFFE, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -2
    61  			less: false,
    62  		},
    63  
    64  		{
    65  			i:    deprecated.Int96{0: 0xFFFFFFFE, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -2
    66  			j:    deprecated.Int96{0: 0xFFFFFFFF, 1: 0xFFFFFFFF, 2: 0xFFFFFFFF}, // -1
    67  			less: true,
    68  		},
    69  	}
    70  
    71  	for _, test := range tests {
    72  		scenario := ""
    73  		if test.less {
    74  			scenario = fmt.Sprintf("%s<%s", test.i, test.j)
    75  		} else {
    76  			scenario = fmt.Sprintf("%s>=%s", test.i, test.j)
    77  		}
    78  		t.Run(scenario, func(t *testing.T) {
    79  			if test.i.Less(test.j) != test.less {
    80  				t.Error("FAIL")
    81  			}
    82  			if test.less {
    83  				if test.j.Less(test.i) {
    84  					t.Error("FAIL (inverse)")
    85  				}
    86  			}
    87  		})
    88  	}
    89  }
    90  
    91  func TestMaxLenInt96(t *testing.T) {
    92  	for _, test := range []struct {
    93  		data   []deprecated.Int96
    94  		maxlen int
    95  	}{
    96  		{
    97  			data:   nil,
    98  			maxlen: 0,
    99  		},
   100  
   101  		{
   102  			data:   []deprecated.Int96{{}, {}, {}, {}, {}},
   103  			maxlen: 0,
   104  		},
   105  
   106  		{
   107  			data:   []deprecated.Int96{{0: 0x01}, {0: 0xFF}, {1: 0x02}, {0: 0xF0}},
   108  			maxlen: 34,
   109  		},
   110  	} {
   111  		t.Run("", func(t *testing.T) {
   112  			if maxlen := deprecated.MaxLenInt96(test.data); maxlen != test.maxlen {
   113  				t.Errorf("want=%d got=%d", test.maxlen, maxlen)
   114  			}
   115  		})
   116  	}
   117  }