Ejemplo n.º 1
0
 def test_andor_inversion(self):
     domain = [['OR', ['x', '=', 4], ['y', '>', 6]], ['z', '=', 3]]
     self.assertEqual(domain_inversion(domain, 'z'), [['z', '=', 3]])
     self.assertEqual(
         domain_inversion(domain, 'z', {'x': 5}), [['z', '=', 3]])
     self.assertFalse(domain_inversion(domain, 'z', {'x': 5, 'y': 5}))
     self.assertEqual(
         domain_inversion(domain, 'z', {'x': 5, 'y': 7}), [['z', '=', 3]])
Ejemplo n.º 2
0
 def test_orand_inversion(self):
     domain = ['OR', [['x', '=', 3], ['y', '>', 5], ['z', '=', 'abc']],
         [['x', '=', 4]], [['y', '>', 6]]]
     self.assertEqual(domain_inversion(domain, 'x'), True)
     self.assertEqual(domain_inversion(domain, 'x', {'y': 4}), True)
     self.assertEqual(
         domain_inversion(domain, 'x', {'z': 'abc', 'y': 7}), True)
     self.assertEqual(domain_inversion(domain, 'x', {'y': 7}), True)
     self.assertEqual(domain_inversion(domain, 'x', {'z': 'ab'}), True)
Ejemplo n.º 3
0
    def test_simple_inversion(self):
        domain = [['x', '=', 3]]
        self.assertEqual(domain_inversion(domain, 'x'), [['x', '=', 3]])

        domain = []
        self.assertTrue(domain_inversion(domain, 'x'))
        self.assertTrue(domain_inversion(domain, 'x', {'x': 5}))
        self.assertTrue(domain_inversion(domain, 'z', {'x': 7}))

        domain = [['x.id', '>', 5]]
        self.assertEqual(domain_inversion(domain, 'x'), [['x.id', '>', 5]])
Ejemplo n.º 4
0
    def test_andand_inversion(self):
        domain = [[['x', '=', 4], ['y', '>', 6]], ['z', '=', 3]]
        self.assertEqual(domain_inversion(domain, 'z'), [['z', '=', 3]])
        self.assertEqual(
            domain_inversion(domain, 'z', {'x': 5}), [['z', '=', 3]])
        self.assertEqual(domain_inversion(domain, 'z', {'y': 5}), False)
        self.assertEqual(
            domain_inversion(domain, 'z', {'x': 4, 'y': 7}), [['z', '=', 3]])

        domain = [
            [['x', '=', 4], ['y', '>', 6], ['z', '=', 2]], [['w', '=', 2]]]
        self.assertEqual(
            domain_inversion(domain, 'z', {'x': 4}), [['z', '=', 2]])
Ejemplo n.º 5
0
    def test_and_inversion(self):
        domain = [['x', '=', 3], ['y', '>', 5]]
        self.assertEqual(domain_inversion(domain, 'x'), [['x', '=', 3]])
        self.assertFalse(domain_inversion(domain, 'x', {'y': 4}))
        self.assertEqual(domain_inversion(domain, 'x', {'y': 6}),
                         [['x', '=', 3]])

        domain = [['x', '=', 3], ['y', '=', 5]]
        self.assertTrue(domain_inversion(domain, 'z'))
        self.assertTrue(domain_inversion(domain, 'z', {'x': 2, 'y': 7}))
        self.assertEqual(domain_inversion(domain, 'x', {'y': None}),
                         [['x', '=', 3]])

        domain = [['x.id', '>', 5], ['y', '<', 3]]
        self.assertEqual(domain_inversion(domain, 'y'), [['y', '<', 3]])
        self.assertEqual(domain_inversion(domain, 'y', {'x': 3}),
                         [['y', '<', 3]])
        self.assertEqual(domain_inversion(domain, 'x'), [['x.id', '>', 5]])
Ejemplo n.º 6
0
 def test_oror_inversion(self):
     domain = [
         'OR', ['OR', ['x', '=', 3], ['y', '>', 5]],
         ['OR', ['x', '=', 2], ['z', '=', 'abc']],
         ['OR', ['y', '=', 8], ['z', '=', 'y']]
     ]
     self.assertTrue(domain_inversion(domain, 'x'))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 4}))
     self.assertTrue(domain_inversion(domain, 'x', {'z': 'ab'}))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 7}))
     self.assertTrue(domain_inversion(domain, 'x', {'z': 'abc'}))
     self.assertTrue(domain_inversion(domain, 'x', {'z': 'y'}))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 8}))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 8, 'z': 'b'}))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 4, 'z': 'y'}))
     self.assertTrue(domain_inversion(domain, 'x', {'y': 7, 'z': 'abc'}))
     self.assertEqual(domain_inversion(domain, 'x', {
         'y': 4,
         'z': 'b'
     }), ['OR', [['x', '=', 3]], [['x', '=', 2]]])
Ejemplo n.º 7
0
    def test_or_inversion(self):
        domain = ['OR', ['x', '=', 3], ['y', '>', 5], ['z', '=', 'abc']]
        self.assertEqual(domain_inversion(domain, 'x'), [['x', '=', 3]])
        self.assertEqual(domain_inversion(domain, 'x', {'y': 4}),
                         [['x', '=', 3]])
        self.assertEqual(domain_inversion(domain, 'x', {
            'y': 4,
            'z': 'ab'
        }), [['x', '=', 3]])
        self.assertTrue(domain_inversion(domain, 'x', {'y': 7}))
        self.assertTrue(domain_inversion(domain, 'x', {'y': 7, 'z': 'b'}))
        self.assertTrue(domain_inversion(domain, 'x', {'z': 'abc'}))
        self.assertTrue(domain_inversion(domain, 'x', {'y': 4, 'z': 'abc'}))

        domain = ['OR', ['x', '=', 3], ['y', '=', 5]]
        self.assertEqual(domain_inversion(domain, 'x', {'y': None}),
                         [['x', '=', 3]])

        domain = ['OR', ['x', '=', 3], ['y', '>', 5]]
        self.assertTrue(domain_inversion(domain, 'z'))

        domain = ['OR', ['x.id', '>', 5], ['y', '<', 3]]
        self.assertEqual(domain_inversion(domain, 'y'), [['y', '<', 3]])
        self.assertEqual(domain_inversion(domain, 'y', {'z': 4}),
                         [['y', '<', 3]])
        self.assertTrue(domain_inversion(domain, 'y', {'x': 3}))

        domain = ['OR', ['length', '>', 5], ['language.code', '=', 'de_DE']]
        self.assertEqual(
            domain_inversion(domain, 'length', {
                'length': 0,
                'name': 'n'
            }), [['length', '>', 5]])