icza / gox

Minimalistic extension to Go. It means to be a complement to the standard library.
Apache License 2.0
132 stars 14 forks source link

Tests fail to run on 32-bit architectures #6

Closed ssgelm closed 2 years ago

ssgelm commented 2 years ago

Hi,

In building this for Debian I discovered that the math tests fail to run on 32-bit architectures, specifically https://github.com/icza/gox/blob/cd40a3f8d324fde16ff701ef5da3e8e04b652c8d/mathx/mathx_test.go#L17 Because Int is a 32-bit integer on 32-bit architectures, -math.MinInt32 is one too big and causes an overflow. I'm happy to submit a PR to fix this, but I'm not sure how you'd prefer this be fixed. The easiest would be to either remove the test or to add 1 to MinInt32. What would you prefer be done to fix this?

icza commented 2 years ago

Thanks for the note.

I'd like to leave the test, and modify it to expect math.MinInt32 in case of 32-bit architecture, something like this:

cases := []struct {
    name   string
    i, exp int
}{
    {"zero", 0, 0},
    {"pos", 1, 1},
    {"neg", -1, 1},
    {"maxint32", math.MaxInt32, math.MaxInt32},
    // On 32-bit arch, -math.MinInt32 overflows and "becomes" itself:
    {"minint32", math.MinInt32, gox.If(osx.Arch32bit).Int(math.MinInt32, -math.MinInt32)},
}

You may submit a PR with this corrected test if you want to.