Source file src/math/const_test.go

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

View as plain text