github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/itoa/itoa_test.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package itoa_test
     6  
     7  import (
     8  	"fmt"
     9  	"math"
    10  	"testing"
    11  
    12  	"github.com/go-asm/go/itoa"
    13  )
    14  
    15  var (
    16  	minInt64  int64  = math.MinInt64
    17  	maxInt64  int64  = math.MaxInt64
    18  	maxUint64 uint64 = math.MaxUint64
    19  )
    20  
    21  func TestItoa(t *testing.T) {
    22  	tests := []int{int(minInt64), math.MinInt32, -999, -100, -1, 0, 1, 100, 999, math.MaxInt32, int(maxInt64)}
    23  	for _, tt := range tests {
    24  		got := itoa.Itoa(tt)
    25  		want := fmt.Sprint(tt)
    26  		if want != got {
    27  			t.Fatalf("Itoa(%d) = %s, want %s", tt, got, want)
    28  		}
    29  	}
    30  }
    31  
    32  func TestUitoa(t *testing.T) {
    33  	tests := []uint{0, 1, 100, 999, math.MaxUint32, uint(maxUint64)}
    34  	for _, tt := range tests {
    35  		got := itoa.Uitoa(tt)
    36  		want := fmt.Sprint(tt)
    37  		if want != got {
    38  			t.Fatalf("Uitoa(%d) = %s, want %s", tt, got, want)
    39  		}
    40  	}
    41  }
    42  
    43  func TestUitox(t *testing.T) {
    44  	tests := []uint{0, 1, 15, 100, 999, math.MaxUint32, uint(maxUint64)}
    45  	for _, tt := range tests {
    46  		got := itoa.Uitox(tt)
    47  		want := fmt.Sprintf("%#x", tt)
    48  		if want != got {
    49  			t.Fatalf("Uitox(%x) = %s, want %s", tt, got, want)
    50  		}
    51  	}
    52  }