def test_and_lset(): # without axis assert LSet(['a', 'b', 'c']) & LSet(['c', 'd']) == LSet(['c']) alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b', 'c'].named('abc').set() & alpha['c', 'd'].named('cd') assert res.axis is alpha assert res.name == 'abc & cd' assert res == alpha[['c']].set()
def test_and(self): # without axis self.assertEqual(LSet(['a', 'b', 'c']) & LSet(['c', 'd']), LSet(['c'])) # with axis & name alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b', 'c'].named('abc').set() & alpha['c', 'd'].named('cd') self.assertIs(res.axis, alpha) self.assertEqual(res.name, 'abc & cd') self.assertEqual(res, alpha[['c']].set())
def test_or_lset(): # without axis assert LSet(['a', 'b']) | LSet(['c', 'd']) == LSet(['a', 'b', 'c', 'd']) assert LSet(['a', 'b', 'c']) | LSet(['c', 'd']) == LSet( ['a', 'b', 'c', 'd']) alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set() | alpha['c', 'd'].set() assert res.axis is alpha assert res == alpha['a', 'b', 'c', 'd'].set() assert alpha['a', 'b', 'c'].set() | alpha['c', 'd'].set() == alpha['a', 'b', 'c', 'd'].set() alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set() | alpha['c', 'd'] assert res.axis is alpha assert res == alpha['a', 'b', 'c', 'd'].set() assert alpha['a', 'b', 'c'].set() | alpha['c', 'd'] == alpha['a', 'b', 'c', 'd'].set() alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set().named('ab') | alpha['c', 'd'].set().named('cd') assert res.axis is alpha assert res.name == 'ab | cd' assert res == alpha['a', 'b', 'c', 'd'].set() assert alpha['a', 'b', 'c'].set() | alpha['c', 'd'] == alpha['a', 'b', 'c', 'd'].set() num = Axis(range(10), 'num') assert num[1, 5, 3].set() | 4 == num[1, 5, 3, 4].set() assert num[1, 5, 3].set() | num[4] == num[1, 5, 3, 4].set() assert num[4].set() | num[1, 5, 3] == num[4, 1, 5, 3].set() assert num[:2].set() | num[8:] == num[0, 1, 2, 8, 9].set() assert num[:2].set() | num[5] == num[0, 1, 2, 5].set()
def test_or(self): # without axis self.assertEqual( LSet(['a', 'b']) | LSet(['c', 'd']), LSet(['a', 'b', 'c', 'd'])) self.assertEqual( LSet(['a', 'b', 'c']) | LSet(['c', 'd']), LSet(['a', 'b', 'c', 'd'])) # with axis (pure) alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set() | alpha['c', 'd'].set() self.assertIs(res.axis, alpha) self.assertEqual(res, alpha['a', 'b', 'c', 'd'].set()) self.assertEqual(alpha['a', 'b', 'c'].set() | alpha['c', 'd'].set(), alpha['a', 'b', 'c', 'd'].set()) # with axis (mixed) alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set() | alpha['c', 'd'] self.assertIs(res.axis, alpha) self.assertEqual(res, alpha['a', 'b', 'c', 'd'].set()) self.assertEqual(alpha['a', 'b', 'c'].set() | alpha['c', 'd'], alpha['a', 'b', 'c', 'd'].set()) # with axis & name alpha = Axis('alpha=a,b,c,d') res = alpha['a', 'b'].set().named('ab') | alpha['c', 'd'].set().named('cd') self.assertIs(res.axis, alpha) self.assertEqual(res.name, 'ab | cd') self.assertEqual(res, alpha['a', 'b', 'c', 'd'].set()) self.assertEqual(alpha['a', 'b', 'c'].set() | alpha['c', 'd'], alpha['a', 'b', 'c', 'd'].set()) # numeric axis num = Axis(range(10), 'num') # single int self.assertEqual(num[1, 5, 3].set() | 4, num[1, 5, 3, 4].set()) self.assertEqual(num[1, 5, 3].set() | num[4], num[1, 5, 3, 4].set()) self.assertEqual(num[4].set() | num[1, 5, 3], num[4, 1, 5, 3].set()) # slices self.assertEqual(num[:2].set() | num[8:], num[0, 1, 2, 8, 9].set()) self.assertEqual(num[:2].set() | num[5], num[0, 1, 2, 5].set())
def test_sub(self): self.assertEqual(LSet(['a', 'b', 'c']) - LSet(['c', 'd']), LSet(['a', 'b'])) self.assertEqual(LSet(['a', 'b', 'c']) - ['c', 'd'], LSet(['a', 'b'])) self.assertEqual(LSet(['a', 'b', 'c']) - 'b', LSet(['a', 'c'])) self.assertEqual(LSet([1, 2, 3]) - 4, LSet([1, 2, 3])) self.assertEqual(LSet([1, 2, 3]) - 2, LSet([1, 3]))
def test_sub_lset(): assert LSet(['a', 'b', 'c']) - LSet(['c', 'd']) == LSet(['a', 'b']) assert LSet(['a', 'b', 'c']) - ['c', 'd'] == LSet(['a', 'b']) assert LSet(['a', 'b', 'c']) - 'b' == LSet(['a', 'c']) assert LSet([1, 2, 3]) - 4 == LSet([1, 2, 3]) assert LSet([1, 2, 3]) - 2 == LSet([1, 3])