From 3da86925755116e3ca0306fcf4d550aef7b96d67 Mon Sep 17 00:00:00 2001 From: zyd Date: Sat, 14 May 2022 15:18:34 +0900 Subject: [PATCH 1/3] add method split --- README.md | 2 +- ramda/__init__.py | 1 + ramda/split.py | 3 +++ test/test_split.py | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ramda/split.py create mode 100644 test/test_split.py diff --git a/README.md b/README.md index 32dd7be..63a64e1 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,7 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd'] - [x] sort - [x] sortBy - [ ] sortWith -- [ ] split +- [x] split - [ ] splitAt - [ ] splitEvery - [ ] splitWhen diff --git a/ramda/__init__.py b/ramda/__init__.py index 7023271..739dff4 100644 --- a/ramda/__init__.py +++ b/ramda/__init__.py @@ -73,6 +73,7 @@ from .slice import slice from .sort import sort from .sortBy import sortBy +from .split import split from .sum import sum from .T import T from .tail import tail diff --git a/ramda/split.py b/ramda/split.py new file mode 100644 index 0000000..329fee9 --- /dev/null +++ b/ramda/split.py @@ -0,0 +1,3 @@ +from .invoker import invoker + +split = invoker(1, 'split') diff --git a/test/test_split.py b/test/test_split.py new file mode 100644 index 0000000..72d0804 --- /dev/null +++ b/test/test_split.py @@ -0,0 +1,19 @@ + +import unittest + +import ramda as R + +""" +https://github.com/ramda/ramda/blob/master/test/split.js +""" + + +class TestSplit(unittest.TestCase): + def test_splits_a_string_into_an_array(self): + self.assertEqual(['a', 'b', 'c', 'xyz', 'd'], R.split('.', 'a.b.c.xyz.d')) + + def test_the_split_string_can_be_arbitrary(self): + self.assertEqual(['The C', ' in the H', ' s', ' on the m', ''], R.split('at', 'The Cat in the Hat sat on the mat')) + +if __name__ == '__main__': + unittest.main() From c6df234dd6741f7a1b6698cd42747e771f4d3168 Mon Sep 17 00:00:00 2001 From: zyd Date: Sat, 14 May 2022 15:29:33 +0900 Subject: [PATCH 2/3] add method subtract, modify add --- README.md | 16 ++++++++++++---- ramda/__init__.py | 1 + ramda/subtract.py | 4 ++++ test/test_add.py | 6 ++++-- test/test_subtract.py | 26 ++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 ramda/subtract.py create mode 100644 test/test_subtract.py diff --git a/README.md b/README.md index 63a64e1..ff53882 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,9 @@ Functions supported now. - [x] add ```python - # different from ramda, ramda treat null as 0 - >>> R.add(None, None) # float('nan) +# different from ramda +R.add(None, None) # float('nan) +R.add(date(1,2,3), date(1,2,3)) # float('nan) ``` - [ ] addIndex @@ -437,6 +438,13 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd'] - [ ] splitWhenever - [ ] startsWith - [ ] subtract + +```python +# different from ramda +R.subtract(None, None) # float('nan) +R.subtract(date(1,2,3), date(1,2,3)) # float('nan) +``` + - [x] sum - [ ] symmetricDifference - [ ] symmetricDifferenceWith @@ -457,8 +465,8 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd'] Partially supported -- String type, supported -- for others, just use str(x) instead +1. String type, supported +1. for others, just use str(x) instead - [ ] toUpper - [ ] transduce diff --git a/ramda/__init__.py b/ramda/__init__.py index 739dff4..6207cac 100644 --- a/ramda/__init__.py +++ b/ramda/__init__.py @@ -74,6 +74,7 @@ from .sort import sort from .sortBy import sortBy from .split import split +from .subtract import subtract from .sum import sum from .T import T from .tail import tail diff --git a/ramda/subtract.py b/ramda/subtract.py new file mode 100644 index 0000000..2a3fc2f --- /dev/null +++ b/ramda/subtract.py @@ -0,0 +1,4 @@ +from .private._curry2 import _curry2 +from .private._helper import toNumber + +subtract = _curry2(lambda a, b: toNumber(a) - toNumber(b)) diff --git a/test/test_add.py b/test/test_add.py index f560dbd..a922512 100644 --- a/test/test_add.py +++ b/test/test_add.py @@ -1,5 +1,6 @@ -import math import unittest +from datetime import date +from math import isnan import ramda as R @@ -16,7 +17,8 @@ def test_coerces_its_arguments_to_numbers(self): self.assertEqual(3, R.add('1', '2')) self.assertEqual(3, R.add(1, '2')) self.assertEqual(1, R.add(True, False)) - self.assertTrue(math.isnan(R.add(None, None))) + self.assertTrue(isnan(R.add(None, None))) + self.assertTrue(isnan(R.add(date(1, 1, 1), date(2, 1, 1)))) def test_float(self): self.assertEqual(4.2, R.add(1.1, 3.1)) diff --git a/test/test_subtract.py b/test/test_subtract.py new file mode 100644 index 0000000..0c772b0 --- /dev/null +++ b/test/test_subtract.py @@ -0,0 +1,26 @@ + +import unittest +from datetime import date +from math import isnan + +import ramda as R + +""" +https://github.com/ramda/ramda/blob/master/test/subtract.js +""" + + +class TestSubtract(unittest.TestCase): + def test_subtracts_two_numbers(self): + self.assertEqual(15, R.subtract(22, 7)) + + def test_coerces_its_arguments_to_numbers(self): + self.assertEqual(-1, R.subtract('1', '2')) + self.assertEqual(-1, R.subtract(1, '2')) + self.assertEqual(1, R.subtract(True, False)) + self.assertTrue(isnan(R.subtract(None, None))) + self.assertTrue(isnan(R.subtract(date(1, 1, 1), date(2, 1, 1)))) + + +if __name__ == '__main__': + unittest.main() From 51f4497e588299dc9db79225538c76c7a64f78e1 Mon Sep 17 00:00:00 2001 From: zyd Date: Sat, 14 May 2022 15:30:28 +0900 Subject: [PATCH 3/3] mark subtract as added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff53882..151fbae 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,7 @@ R.slice(1, None, ['a', 'b', 'c', 'd']) # ['b', 'c', 'd'] - [ ] splitWhen - [ ] splitWhenever - [ ] startsWith -- [ ] subtract +- [x] subtract ```python # different from ramda