From de11b4e658edf3ea876aaea3d3d681eaec13dcc4 Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Thu, 3 Jul 2014 15:16:21 +0200 Subject: [PATCH] Swap order of symbols and Dummy --- pypol/__init__.py | 4 ++-- pypol/linexprs.py | 14 +++++++------- pypol/tests/test_linexprs.py | 21 ++++++++++++++++----- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/pypol/__init__.py b/pypol/__init__.py index c81cb25..e39bce7 100644 --- a/pypol/__init__.py +++ b/pypol/__init__.py @@ -2,13 +2,13 @@ A polyhedral library based on ISL. """ -from .linexprs import Expression, Symbol, symbols, Dummy, Rational +from .linexprs import Expression, Symbol, Dummy, symbols, Rational from .polyhedra import Polyhedron, Eq, Ne, Le, Lt, Ge, Gt, Ne, Empty, Universe from .domains import Domain, And, Or, Not __all__ = [ - 'Expression', 'Symbol', 'symbols', 'Dummy', 'Rational', + 'Expression', 'Symbol', 'Dummy', 'symbols', 'Rational', 'Polyhedron', 'Eq', 'Ne', 'Le', 'Lt', 'Ge', 'Gt', 'Empty', 'Universe', 'Domain', 'And', 'Or', 'Not', ] diff --git a/pypol/linexprs.py b/pypol/linexprs.py index f3cff23..ef5d90b 100644 --- a/pypol/linexprs.py +++ b/pypol/linexprs.py @@ -9,7 +9,7 @@ from fractions import Fraction, gcd __all__ = [ 'Expression', - 'Symbol', 'symbols', 'Dummy', + 'Symbol', 'Dummy', 'symbols', 'Rational', ] @@ -415,12 +415,6 @@ class Symbol(Expression): raise TypeError('expr must be a sympy.Symbol instance') -def symbols(names): - if isinstance(names, str): - names = names.replace(',', ' ').split() - return tuple(Symbol(name) for name in names) - - class Dummy(Symbol): __slots__ = ( @@ -449,6 +443,12 @@ class Dummy(Symbol): return isinstance(other, Dummy) and self._index == other._index +def symbols(names): + if isinstance(names, str): + names = names.replace(',', ' ').split() + return tuple(Symbol(name) for name in names) + + class Rational(Expression): __slots__ = ( diff --git a/pypol/tests/test_linexprs.py b/pypol/tests/test_linexprs.py index 508c57b..4c27b21 100644 --- a/pypol/tests/test_linexprs.py +++ b/pypol/tests/test_linexprs.py @@ -225,11 +225,6 @@ class TestSymbol(unittest.TestCase): with self.assertRaises(TypeError): Symbol.fromsympy(sp_x*sp_x) - def test_symbols(self): - self.assertListEqual(list(symbols('x y')), [self.x, self.y]) - self.assertListEqual(list(symbols('x,y')), [self.x, self.y]) - self.assertListEqual(list(symbols(['x', 'y'])), [self.x, self.y]) - class TestDummy(unittest.TestCase): @@ -248,6 +243,22 @@ class TestDummy(unittest.TestCase): self.assertNotEqual(Dummy(), Dummy()) +class TestSymbols(unittest.TestCase): + + def setUp(self): + self.x = Symbol('x') + self.y = Symbol('y') + + def test(self): + self.assertListEqual(list(symbols('x y')), [self.x, self.y]) + self.assertListEqual(list(symbols('x,y')), [self.x, self.y]) + self.assertListEqual(list(symbols(['x', 'y'])), [self.x, self.y]) + with self.assertRaises(TypeError): + symbols(1) + with self.assertRaises(TypeError): + symbols(['a', 1]) + + class TestRational(unittest.TestCase): def setUp(self): -- 2.20.1