github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/cmpconn/compare_test.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package cmpconn
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/cockroachdb/apd"
    17  )
    18  
    19  func TestCompareVals(t *testing.T) {
    20  	for i, tc := range []struct {
    21  		equal bool
    22  		a, b  []interface{}
    23  	}{
    24  		{
    25  			equal: true,
    26  			a:     []interface{}{apd.New(-2, 0)},
    27  			b:     []interface{}{apd.New(-2, 0)},
    28  		},
    29  		{
    30  			equal: true,
    31  			a:     []interface{}{apd.New(2, 0)},
    32  			b:     []interface{}{apd.New(2, 0)},
    33  		},
    34  		{
    35  			equal: false,
    36  			a:     []interface{}{apd.New(2, 0)},
    37  			b:     []interface{}{apd.New(-2, 0)},
    38  		},
    39  		{
    40  			equal: true,
    41  			a:     []interface{}{apd.New(2, 0)},
    42  			b:     []interface{}{apd.New(2000001, -6)},
    43  		},
    44  		{
    45  			equal: false,
    46  			a:     []interface{}{apd.New(2, 0)},
    47  			b:     []interface{}{apd.New(200001, -5)},
    48  		},
    49  		{
    50  			equal: false,
    51  			a:     []interface{}{apd.New(-2, 0)},
    52  			b:     []interface{}{apd.New(-200001, -5)},
    53  		},
    54  		{
    55  			equal: false,
    56  			a:     []interface{}{apd.New(2, 0)},
    57  			b:     []interface{}{apd.New(-2000001, -6)},
    58  		},
    59  	} {
    60  		err := CompareVals(tc.a, tc.b)
    61  		equal := err == nil
    62  		if equal != tc.equal {
    63  			t.Log("test index", i)
    64  			if err != nil {
    65  				t.Fatal(err)
    66  			} else {
    67  				t.Fatal("expected unequal")
    68  			}
    69  		}
    70  	}
    71  }