• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

enetx / g / 14661178371

25 Apr 2025 09:14AM UTC coverage: 86.248% (-0.2%) from 86.478%
14661178371

push

github

enetx
ref

124 of 174 new or added lines in 13 files covered. (71.26%)

1 existing line in 1 file now uncovered.

3462 of 4014 relevant lines covered (86.25%)

127.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.74
/int.go
1
package g
2

3
import (
4
        "encoding/binary"
5
        "fmt"
6
        "math/big"
7
        "math/bits"
8
        "strconv"
9

10
        "github.com/enetx/g/cmp"
11
        "github.com/enetx/g/pkg/constraints"
12
        "github.com/enetx/g/pkg/rand"
13
)
14

15
// NewInt creates a new Int with the provided int value.
16
func NewInt[T constraints.Integer | rune | byte](i T) Int { return Int(i) }
4✔
17

18
// Ptr returns a pointer to the current Int value.
19
func (i Int) Ptr() *Int { return &i }
1✔
20

21
// Transform applies a transformation function to the Int and returns the result.
22
func (i Int) Transform(fn func(Int) Int) Int { return fn(i) }
2✔
23

24
// Min returns the minimum of Ints.
25
func (i Int) Min(b ...Int) Int { return cmp.Min(append(b, i)...) }
1,827✔
26

27
// Max returns the maximum of Ints.
28
func (i Int) Max(b ...Int) Int { return cmp.Max(append(b, i)...) }
23✔
29

30
// RandomRange returns a random Int in the range [from, to].
31
func (i Int) RandomRange(to Int) Int { return rand.N(to-i+1) + i }
402✔
32

33
// Bytes returns the Int as a byte slice.
34
func (i Int) Bytes() Bytes {
4✔
35
        buffer := make([]byte, 8)
4✔
36
        binary.BigEndian.PutUint64(buffer, i.UInt64())
4✔
37

4✔
38
        return buffer[bits.LeadingZeros64(i.UInt64())>>3:]
4✔
39
}
4✔
40

41
// Abs returns the absolute value of the Int.
42
func (i Int) Abs() Int { return i.Float().Abs().Int() }
4✔
43

44
// Add adds two Ints and returns the result.
45
func (i Int) Add(b Int) Int { return i + b }
1,013✔
46

47
// BigInt returns the Int as a *big.Int.
48
func (i Int) BigInt() *big.Int { return big.NewInt(i.Int64()) }
1✔
49

50
// Div divides two Ints and returns the result.
51
func (i Int) Div(b Int) Int { return i / b }
1✔
52

53
// Eq checks if two Ints are equal.
54
func (i Int) Eq(b Int) bool { return i == b }
8✔
55

56
// Gt checks if the Int is greater than the specified Int.
57
func (i Int) Gt(b Int) bool { return i > b }
100✔
58

59
// Gte checks if the Int is greater than or equal to the specified Int.
60
func (i Int) Gte(b Int) bool { return i >= b }
566✔
61

62
// Float returns the Int as an Float.
63
func (i Int) Float() Float { return Float(i) }
48✔
64

65
// String returns the Int as an String.
66
func (i Int) String() String { return String(strconv.Itoa(int(i))) }
137✔
67

68
// Std returns the Int as an int.
69
func (i Int) Std() int { return int(i) }
792✔
70

71
// Cmp compares two Ints and returns an cmp.Ordering.
72
func (i Int) Cmp(b Int) cmp.Ordering { return cmp.Cmp(i, b) }
3✔
73

74
// Int16 returns the Int as an int16.
75
func (i Int) Int16() int16 { return int16(i) }
1✔
76

77
// Int32 returns the Int as an int32.
78
func (i Int) Int32() int32 { return int32(i) }
2✔
79

80
// Int64 returns the Int as an int64.
81
func (i Int) Int64() int64 { return int64(i) }
1✔
82

83
// Int8 returns the Int as an int8.
84
func (i Int) Int8() int8 { return int8(i) }
3✔
85

86
// IsZero checks if the Int is 0.
87
func (i Int) IsZero() bool { return i.Eq(0) }
2✔
88

89
// IsNegative checks if the Int is negative.
90
func (i Int) IsNegative() bool { return i.Lt(0) }
470✔
91

92
// IsPositive checks if the Int is positive.
93
func (i Int) IsPositive() bool { return i.Gte(0) }
403✔
94

95
// Lt checks if the Int is less than the specified Int.
96
func (i Int) Lt(b Int) bool { return i < b }
602✔
97

98
// Lte checks if the Int is less than or equal to the specified Int.
99
func (i Int) Lte(b Int) bool { return i <= b }
13✔
100

101
// Mul multiplies two Ints and returns the result.
102
func (i Int) Mul(b Int) Int { return i * b }
2✔
103

104
// Ne checks if two Ints are not equal.
105
func (i Int) Ne(b Int) bool { return i != b }
2✔
106

107
// Random returns a random Int in the range [0, hi].
108
func (i Int) Random() Int { return Int(0).RandomRange(i) }
200✔
109

110
// Rem returns the remainder of the division between the receiver and the input value.
111
func (i Int) Rem(b Int) Int { return i % b }
7✔
112

113
// Sub subtracts two Ints and returns the result.
114
func (i Int) Sub(b Int) Int { return i - b }
5✔
115

116
// Binary returns the Int as a binary string.
117
func (i Int) Binary() String { return String(fmt.Sprintf("%08b", i)) }
9✔
118

119
// Hex returns the Int as a hexadecimal string.
120
func (i Int) Hex() String { return String(fmt.Sprintf("%x", i)) }
18✔
121

122
// Octal returns the Int as an octal string.
123
func (i Int) Octal() String { return String(fmt.Sprintf("%o", i)) }
13✔
124

125
// UInt returns the Int as a uint.
126
func (i Int) UInt() uint { return uint(i) }
2✔
127

128
// UInt16 returns the Int as a uint16.
129
func (i Int) UInt16() uint16 { return uint16(i) }
2✔
130

131
// UInt32 returns the Int as a uint32.
132
func (i Int) UInt32() uint32 { return uint32(i) }
2✔
133

134
// UInt64 returns the Int as a uint64.
135
func (i Int) UInt64() uint64 { return uint64(i) }
8✔
136

137
// UInt8 returns the Int as a uint8.
138
func (i Int) UInt8() uint8 { return uint8(i) }
3✔
139

140
// Print writes the value of the Int to the standard output (console)
141
// and returns the Int unchanged.
NEW
142
func (i Int) Print() Int { fmt.Print(i); return i }
×
143

144
// Println writes the value of the Int to the standard output (console) with a newline
145
// and returns the Int unchanged.
NEW
146
func (i Int) Println() Int { fmt.Println(i); return i }
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc