Skip to content

Commit 21067a4

Browse files
no-longer-on-githu-bpaf31
authored andcommitted
Fix intDegree on edge cases (#114)
* Fix intDegree on edge cases Fixes #113. * Make sure degree is always non-negative
1 parent 655765c commit 21067a4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Data/EuclideanRing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
exports.intDegree = function (x) {
4-
return Math.abs(x);
4+
return Math.min(Math.abs(x), 2147483647);
55
};
66

77
exports.intDiv = function (x) {

test/Test/Main.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ main :: AlmostEff
88
main = do
99
testNumberShow show
1010
testOrderings
11+
testIntDegree
1112

1213
foreign import testNumberShow :: (Number -> String) -> AlmostEff
1314
foreign import throwErr :: String -> AlmostEff
@@ -71,3 +72,10 @@ testOrderings = do
7172
testOrd [1, 1] [1, 0] GT
7273
testOrd [1, -1] [1, 0] LT
7374

75+
testIntDegree :: AlmostEff
76+
testIntDegree = do
77+
let bot = bottom :: Int
78+
assert "degree returns absolute integers" $ degree (-4) == 4
79+
assert "degree returns absolute integers" $ degree 4 == 4
80+
assert "degree returns absolute integers" $ degree bot >= 0
81+
assert "degree does not return out-of-bounds integers" $ degree bot <= top

0 commit comments

Comments
 (0)