const_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. package math_test
  5. import (
  6. "testing"
  7. . "math"
  8. )
  9. func TestMaxUint(t *testing.T) {
  10. if v := uint(MaxUint); v+1 != 0 {
  11. t.Errorf("MaxUint should wrap around to zero: %d", v+1)
  12. }
  13. if v := uint8(MaxUint8); v+1 != 0 {
  14. t.Errorf("MaxUint8 should wrap around to zero: %d", v+1)
  15. }
  16. if v := uint16(MaxUint16); v+1 != 0 {
  17. t.Errorf("MaxUint16 should wrap around to zero: %d", v+1)
  18. }
  19. if v := uint32(MaxUint32); v+1 != 0 {
  20. t.Errorf("MaxUint32 should wrap around to zero: %d", v+1)
  21. }
  22. if v := uint64(MaxUint64); v+1 != 0 {
  23. t.Errorf("MaxUint64 should wrap around to zero: %d", v+1)
  24. }
  25. }
  26. func TestMaxInt(t *testing.T) {
  27. if v := int(MaxInt); v+1 != MinInt {
  28. t.Errorf("MaxInt should wrap around to MinInt: %d", v+1)
  29. }
  30. if v := int8(MaxInt8); v+1 != MinInt8 {
  31. t.Errorf("MaxInt8 should wrap around to MinInt8: %d", v+1)
  32. }
  33. if v := int16(MaxInt16); v+1 != MinInt16 {
  34. t.Errorf("MaxInt16 should wrap around to MinInt16: %d", v+1)
  35. }
  36. if v := int32(MaxInt32); v+1 != MinInt32 {
  37. t.Errorf("MaxInt32 should wrap around to MinInt32: %d", v+1)
  38. }
  39. if v := int64(MaxInt64); v+1 != MinInt64 {
  40. t.Errorf("MaxInt64 should wrap around to MinInt64: %d", v+1)
  41. }
  42. }