github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/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 "internal/itoa" 10 "math" 11 "testing" 12 ) 13 14 var ( 15 minInt64 int64 = math.MinInt64 16 maxInt64 int64 = math.MaxInt64 17 maxUint64 uint64 = math.MaxUint64 18 ) 19 20 func TestItoa(t *testing.T) { 21 tests := []int{int(minInt64), math.MinInt32, -999, -100, -1, 0, 1, 100, 999, math.MaxInt32, int(maxInt64)} 22 for _, tt := range tests { 23 got := itoa.Itoa(tt) 24 want := fmt.Sprint(tt) 25 if want != got { 26 t.Fatalf("Itoa(%d) = %s, want %s", tt, got, want) 27 } 28 } 29 } 30 31 func TestUitoa(t *testing.T) { 32 tests := []uint{0, 1, 100, 999, math.MaxUint32, uint(maxUint64)} 33 for _, tt := range tests { 34 got := itoa.Uitoa(tt) 35 want := fmt.Sprint(tt) 36 if want != got { 37 t.Fatalf("Uitoa(%d) = %s, want %s", tt, got, want) 38 } 39 } 40 }