github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/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/hxx258456/ccgo/internal/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  }