github.com/tursom/GoCollections@v0.3.10/lang/UInt_test.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package lang
     8  
     9  import (
    10  	"testing"
    11  )
    12  
    13  func TestUInt_HashCode(t *testing.T) {
    14  	type Tests struct {
    15  		name string
    16  		i    UInt
    17  		want int32
    18  	}
    19  	var tests []Tests
    20  	for i := 0; i < 10; i++ {
    21  		// -i - 1 is ^i
    22  		// hash code of ^i equals i
    23  		tests = append(tests, Tests{"test -1", UInt(-i - 1), int32(i)})
    24  	}
    25  
    26  	for _, tt := range tests {
    27  		t.Run(tt.name, func(t *testing.T) {
    28  			if got := tt.i.HashCode(); got != tt.want {
    29  				t.Errorf("HashCode() = %v, want %v", got, tt.want)
    30  			}
    31  		})
    32  	}
    33  }