Skip to content

Commit

Permalink
Assert that Min and Max retain precision for large integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale committed Nov 28, 2021
1 parent 960953d commit 5a833e6
Showing 1 changed file with 76 additions and 36 deletions.
112 changes: 76 additions & 36 deletions gmath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ func TestAbs(t *testing.T) {
want: math.Inf(1),
},
{
input: Inf[float64](1),
want: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: Inf[float64](-1),
want: Inf[float64](1),
input: math.Inf(-1),
want: math.Inf(1),
},
{
input: NaN[float64](),
want: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
for _, test := range tests {
Expand Down Expand Up @@ -321,19 +321,19 @@ func TestCopysign(t *testing.T) {
want: math.MaxFloat64,
},
{
input: [2]float64{Inf[float64](1), -5},
want: Inf[float64](-1),
input: [2]float64{math.Inf(1), -5},
want: math.Inf(-1),
},
{
input: [2]float64{Inf[float64](-1), 5},
want: Inf[float64](1),
input: [2]float64{math.Inf(-1), 5},
want: math.Inf(1),
},
{
input: [2]float64{NaN[float64](), 5},
want: NaN[float64](),
input: [2]float64{math.NaN(), 5},
want: math.NaN(),
},
{
input: [2]float64{-3, NaN[float64]()},
input: [2]float64{-3, math.NaN()},
want: 3,
},
}
Expand Down Expand Up @@ -453,15 +453,15 @@ func TestDim(t *testing.T) {
want: 0,
},
{
input: [2]float64{Inf[float64](1), Inf[float64](1)},
input: [2]float64{math.Inf(1), math.Inf(1)},
want: math.NaN(),
},
{
input: [2]float64{Inf[float64](-1), Inf[float64](-1)},
input: [2]float64{math.Inf(-1), math.Inf(-1)},
want: math.NaN(),
},
{
input: [2]float64{NaN[float64](), 1},
input: [2]float64{math.NaN(), 1},
want: math.NaN(),
},
}
Expand Down Expand Up @@ -508,11 +508,11 @@ func TestIsInf(t *testing.T) {
want: false,
},
{
input: [2]interface{}{Inf[float64](1), 1},
input: [2]interface{}{math.Inf(1), 1},
want: true,
},
{
input: [2]interface{}{Inf[float64](1), -1},
input: [2]interface{}{math.Inf(1), -1},
want: false,
},
}
Expand Down Expand Up @@ -811,15 +811,15 @@ func TestLog(t *testing.T) {
want: 2.302585092994046,
},
{
input: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: 0,
want: math.Inf(-1),
},
{
input: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
Expand Down Expand Up @@ -989,15 +989,15 @@ func TestLog10(t *testing.T) {
want: 1,
},
{
input: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: 0,
want: math.Inf(-1),
},
{
input: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
Expand Down Expand Up @@ -1183,11 +1183,11 @@ func TestLog1p(t *testing.T) {
want: math.NaN(),
},
{
input: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
Expand Down Expand Up @@ -1349,15 +1349,15 @@ func TestLog2(t *testing.T) {
want: 3.321928094887362,
},
{
input: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: 0,
want: math.Inf(-1),
},
{
input: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
Expand Down Expand Up @@ -1478,15 +1478,15 @@ func TestLogb(t *testing.T) {
want: 3,
},
{
input: Inf[float64](1),
input: math.Inf(1),
want: math.Inf(1),
},
{
input: 0,
want: math.Inf(-1),
},
{
input: NaN[float64](),
input: math.NaN(),
want: math.NaN(),
},
}
Expand All @@ -1509,10 +1509,6 @@ func TestMax(t *testing.T) {
input: [2]myInt{3, 1},
want: 3,
},
{
input: [2]myInt{-3, -1},
want: -1,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1534,6 +1530,14 @@ func TestMax(t *testing.T) {
input: [2]int{-3, -1},
want: -1,
},
{
input: [2]int{math.MaxInt, math.MaxInt},
want: math.MaxInt,
},
{
input: [2]int{math.MinInt, math.MinInt},
want: math.MinInt,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1555,6 +1559,14 @@ func TestMax(t *testing.T) {
input: [2]int64{-3, -1},
want: -1,
},
{
input: [2]int64{math.MaxInt64, math.MaxInt64},
want: math.MaxInt64,
},
{
input: [2]int64{math.MinInt64, math.MinInt64},
want: math.MinInt64,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1576,6 +1588,10 @@ func TestMax(t *testing.T) {
input: [2]uint{2, 4},
want: 4,
},
{
input: [2]uint{math.MaxUint, math.MaxUint},
want: math.MaxUint,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1597,6 +1613,10 @@ func TestMax(t *testing.T) {
input: [2]uint64{2, 4},
want: 4,
},
{
input: [2]uint64{math.MaxUint64, math.MaxUint64},
want: math.MaxUint64,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand Down Expand Up @@ -1691,10 +1711,6 @@ func TestMin(t *testing.T) {
input: [2]myInt{3, 1},
want: 1,
},
{
input: [2]myInt{-3, -1},
want: -3,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1716,6 +1732,14 @@ func TestMin(t *testing.T) {
input: [2]int{-3, -1},
want: -3,
},
{
input: [2]int{math.MaxInt, math.MaxInt},
want: math.MaxInt,
},
{
input: [2]int{math.MinInt, math.MinInt},
want: math.MinInt,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1737,6 +1761,14 @@ func TestMin(t *testing.T) {
input: [2]int64{-3, -1},
want: -3,
},
{
input: [2]int64{math.MaxInt64, math.MaxInt64},
want: math.MaxInt64,
},
{
input: [2]int64{math.MinInt64, math.MinInt64},
want: math.MinInt64,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1758,6 +1790,10 @@ func TestMin(t *testing.T) {
input: [2]uint{2, 4},
want: 2,
},
{
input: [2]uint{math.MaxUint, math.MaxUint},
want: math.MaxUint,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand All @@ -1779,6 +1815,10 @@ func TestMin(t *testing.T) {
input: [2]uint64{2, 4},
want: 2,
},
{
input: [2]uint64{math.MaxUint64, math.MaxUint64},
want: math.MaxUint64,
},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.input), func(t *testing.T) {
Expand Down

0 comments on commit 5a833e6

Please sign in to comment.