Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ R.length(ObjWithoutLength()) # float('nan')
- [ ] mapAccumRight
- [ ] mapObjIndexed
- [x] 0.1.2 match
- [ ] mathMod
- [x] mathMod
- [x] 0.1.2 Max (`max` is a keyword in python)

If R.Max(a, b)
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .lte import lte
from .map import map
from .match import match
from .mathMod import mathMod
from .Max import Max
from .Min import Min
from .modulo import modulo
Expand Down
13 changes: 13 additions & 0 deletions ramda/mathMod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .private._curry2 import _curry2
from .private._isInteger import _isInteger


def inner_mathMod(m, p):
if not _isInteger(m):
return float('nan')
if not _isInteger(p) or p < 1:
return float('nan')
return m % p


mathMod = _curry2(inner_mathMod)
25 changes: 25 additions & 0 deletions test/test_mathMod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import unittest
from math import isnan

import ramda as R

"""
https://github.com/ramda/ramda/blob/master/test/mathMod.js
"""


class TestMathMod(unittest.TestCase):
def test_requires_integer_arguments(self):
self.assertTrue(isnan(R.mathMod('s', 3)))
self.assertTrue(isnan(R.mathMod(3, 's')))
self.assertTrue(isnan(R.mathMod(12.2, 3)))
self.assertTrue(isnan(R.mathMod(3, 12.2)))

def test_computes_the_true_modulo_function(self):
self.assertEqual(3, R.mathMod(-17, 5))
self.assertEqual(2, R.mathMod(17, 5))
self.assertEqual(3, R.mathMod(15, 12))

if __name__ == '__main__':
unittest.main()