From ba599f762af1907b3ddf9526d6cd386d4c95a890 Mon Sep 17 00:00:00 2001 From: Malkhan Singh Date: Sat, 10 Mar 2018 19:40:27 +0530 Subject: [PATCH 1/5] Correct function def of gray_to_bin and bin_to_gray --- sympy/combinatorics/graycode.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sympy/combinatorics/graycode.py b/sympy/combinatorics/graycode.py index 8e67f587954a..9cc2b702ae27 100644 --- a/sympy/combinatorics/graycode.py +++ b/sympy/combinatorics/graycode.py @@ -329,11 +329,17 @@ def gray_to_bin(bin_list): Examples ======== - + >>> from sympy.combinatorics.graycode import gray_to_bin >>> gray_to_bin('100') '111' + example taken from issue #117 from:- https://github.com/sympy/sympy-live/issues/117 + >>>gtay_to_bin('0001000010100') + '0001111100111' + >>>gray_to_bin('0001000010101') + '0001111100110' + See Also ======== bin_to_gray @@ -357,13 +363,20 @@ def bin_to_gray(bin_list): >>> bin_to_gray('111') '100' + example taken from issue #117 from:- https://github.com/sympy/sympy-live/issues/117 + >>>bin_to_gray('0001111100111') + '0001000010100' + >>>bin_to_gray('0001111100110') + '0001000010101' + + See Also ======== gray_to_bin """ b = [bin_list[0]] - for i in range(0, len(bin_list) - 1): - b += str(int(bin_list[i]) ^ int(b[i - 1])) + for i in range(1, len(bin_list)): + b += str(int(bin_list[i]) ^ int(bin_list[i - 1])) return ''.join(b) From f6c4f511a0f7497f2dae39a9200f4b435240db7b Mon Sep 17 00:00:00 2001 From: Malkhan Singh Date: Sun, 11 Mar 2018 09:37:27 +0530 Subject: [PATCH 2/5] Add a test in test_graycode.py --- sympy/combinatorics/graycode.py | 2 +- sympy/combinatorics/tests/test_graycode.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sympy/combinatorics/graycode.py b/sympy/combinatorics/graycode.py index 9cc2b702ae27..13888501ca02 100644 --- a/sympy/combinatorics/graycode.py +++ b/sympy/combinatorics/graycode.py @@ -335,7 +335,7 @@ def gray_to_bin(bin_list): '111' example taken from issue #117 from:- https://github.com/sympy/sympy-live/issues/117 - >>>gtay_to_bin('0001000010100') + >>>gray_to_bin('0001000010100') '0001111100111' >>>gray_to_bin('0001000010101') '0001111100110' diff --git a/sympy/combinatorics/tests/test_graycode.py b/sympy/combinatorics/tests/test_graycode.py index d67e97d31610..7bc96702111f 100644 --- a/sympy/combinatorics/tests/test_graycode.py +++ b/sympy/combinatorics/tests/test_graycode.py @@ -55,3 +55,9 @@ def test_graycode(): assert list(graycode_subsets(['a', 'b', 'c'])) == \ [[], ['c'], ['b', 'c'], ['b'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'c'], ['a']] + +def test_live_issue_117(): + assert bin_to_gray('0100') == '0110' + assert bin_to_gray('0101') == '0111' + for bits in ('0100', '0101'): + assert gray_to_bin(bin_to_gray(bits)) == bits \ No newline at end of file From 7a45ec9b04892d1f599643157a3d035ea4d58534 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 13 Mar 2018 00:03:54 -0500 Subject: [PATCH 3/5] remove docstring examples Examples are included in the test suite. --- sympy/combinatorics/graycode.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/sympy/combinatorics/graycode.py b/sympy/combinatorics/graycode.py index 13888501ca02..8c84868f5c5c 100644 --- a/sympy/combinatorics/graycode.py +++ b/sympy/combinatorics/graycode.py @@ -329,17 +329,11 @@ def gray_to_bin(bin_list): Examples ======== - + >>> from sympy.combinatorics.graycode import gray_to_bin >>> gray_to_bin('100') '111' - example taken from issue #117 from:- https://github.com/sympy/sympy-live/issues/117 - >>>gray_to_bin('0001000010100') - '0001111100111' - >>>gray_to_bin('0001000010101') - '0001111100110' - See Also ======== bin_to_gray @@ -363,13 +357,6 @@ def bin_to_gray(bin_list): >>> bin_to_gray('111') '100' - example taken from issue #117 from:- https://github.com/sympy/sympy-live/issues/117 - >>>bin_to_gray('0001111100111') - '0001000010100' - >>>bin_to_gray('0001111100110') - '0001000010101' - - See Also ======== gray_to_bin From dbe5ea5161eedea9e87454bcd25d4790abf733cb Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 13 Mar 2018 00:06:14 -0500 Subject: [PATCH 4/5] Update test_graycode.py Add newline. Note: doctests taken from issue at https://github.com/sympy/sympy-live/issues/117 --- sympy/combinatorics/tests/test_graycode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sympy/combinatorics/tests/test_graycode.py b/sympy/combinatorics/tests/test_graycode.py index 7bc96702111f..1e83a0319968 100644 --- a/sympy/combinatorics/tests/test_graycode.py +++ b/sympy/combinatorics/tests/test_graycode.py @@ -60,4 +60,4 @@ def test_live_issue_117(): assert bin_to_gray('0100') == '0110' assert bin_to_gray('0101') == '0111' for bits in ('0100', '0101'): - assert gray_to_bin(bin_to_gray(bits)) == bits \ No newline at end of file + assert gray_to_bin(bin_to_gray(bits)) == bits From b7d0054d6a878bc778f0e041cbc61b224aecd027 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Tue, 13 Mar 2018 08:01:33 -0500 Subject: [PATCH 5/5] import gray_to_bin --- sympy/combinatorics/tests/test_graycode.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sympy/combinatorics/tests/test_graycode.py b/sympy/combinatorics/tests/test_graycode.py index 1e83a0319968..8864a8b9ce6b 100644 --- a/sympy/combinatorics/tests/test_graycode.py +++ b/sympy/combinatorics/tests/test_graycode.py @@ -1,5 +1,6 @@ from sympy.combinatorics.graycode import (GrayCode, bin_to_gray, - random_bitstring, get_subset_from_bitstring, graycode_subsets) + random_bitstring, get_subset_from_bitstring, graycode_subsets, + gray_to_bin) def test_graycode():