Ejemplo n.º 1
0
    def test_div_round_to_zero(self):
        target = BoundedValue(min=9, max=17)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.DIV)
        self.assertEqual(target.min, 2)
        self.assertEqual(target.max, 8)

        target = BoundedValue(min=9, max=17)
        source = BoundedValue(min=-2, max=-4)
        apply_bounded_instruction(target, source, InstructionType.DIV)
        self.assertEqual(target.min, -8)
        self.assertEqual(target.max, -2)

        target = BoundedValue(min=-9, max=-17)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.DIV)
        self.assertEqual(target.min, -8)
        self.assertEqual(target.max, -2)

        target = BoundedValue(min=-17, max=9)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.DIV)
        self.assertEqual(target.min, -8)
        self.assertEqual(target.max, 4)

        target = BoundedValue(min=-17, max=9)
        source = BoundedValue(min=-2, max=4)
        apply_bounded_instruction(target, source, InstructionType.DIV)
        self.assertEqual(target.min, -4)
        self.assertEqual(target.max, 8)
Ejemplo n.º 2
0
    def test_mul(self):
        target = BoundedValue(min=8, max=16)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.MUL)
        self.assertEqual(target.min, 16)
        self.assertEqual(target.max, 64)

        target = BoundedValue(min=9, max=17)
        source = BoundedValue(min=-2, max=-4)
        apply_bounded_instruction(target, source, InstructionType.MUL)
        self.assertEqual(target.min, -68)
        self.assertEqual(target.max, -18)

        target = BoundedValue(min=-9, max=-17)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.MUL)
        self.assertEqual(target.min, -68)
        self.assertEqual(target.max, -18)

        target = BoundedValue(min=-17, max=9)
        source = BoundedValue(min=2, max=4)
        apply_bounded_instruction(target, source, InstructionType.MUL)
        self.assertEqual(target.min, -68)
        self.assertEqual(target.max, 36)

        target = BoundedValue(min=-17, max=9)
        source = BoundedValue(min=-2, max=4)
        apply_bounded_instruction(target, source, InstructionType.MUL)
        self.assertEqual(target.min, -68)
        self.assertEqual(target.max, 36)
Ejemplo n.º 3
0
 def test_add(self):
     target = BoundedValue(min=1, max=3)
     source = BoundedValue(min=2, max=5)
     apply_bounded_instruction(target, source, InstructionType.ADD)
     self.assertEqual(target.min, 3)
     self.assertEqual(target.max, 8)
     self.assertEqual(source.min, 2)
     self.assertEqual(source.max, 5)
Ejemplo n.º 4
0
 def test_mod_lhs_short(self):
     target = BoundedValue(min=0, max=8)
     source = BoundedValue(min=1, max=16)
     apply_bounded_instruction(target, source, InstructionType.MOD)
     self.assertEqual(target.min, 0)
     self.assertEqual(target.max, 8)
Ejemplo n.º 5
0
 def test_mod_exact_both(self):
     target = BoundedValue(min=9, max=9)
     source = BoundedValue(min=8, max=8)
     apply_bounded_instruction(target, source, InstructionType.MOD)
     self.assertEqual(target.min, 1)
     self.assertEqual(target.max, 1)
Ejemplo n.º 6
0
 def test_mod_exact_target(self):
     target = BoundedValue(min=7, max=7)
     source = BoundedValue(min=1, max=8)
     apply_bounded_instruction(target, source, InstructionType.MOD)
     self.assertEqual(target.min, 0)
     self.assertEqual(target.max, 7)
Ejemplo n.º 7
0
 def test_mod_reduced_range(self):
     target = BoundedValue(min=3, max=5)
     source = BoundedValue(min=8, max=16)
     apply_bounded_instruction(target, source, InstructionType.MOD)
     self.assertEqual(target.min, 3)
     self.assertEqual(target.max, 5)
Ejemplo n.º 8
0
 def test_mod_overlap(self):
     target = BoundedValue(min=0, max=100)
     source = BoundedValue(min=1, max=16)
     apply_bounded_instruction(target, source, InstructionType.MOD)
     self.assertEqual(target.min, 0)
     self.assertEqual(target.max, 15)
Ejemplo n.º 9
0
 def test_eql_exact(self):
     target = BoundedValue(min=16, max=16)
     source = BoundedValue(min=16, max=16)
     apply_bounded_instruction(target, source, InstructionType.EQUALS)
     self.assertEqual(target.min, 1)
     self.assertEqual(target.max, 1)
Ejemplo n.º 10
0
 def test_eql_overlap(self):
     target = BoundedValue(min=8, max=16)
     source = BoundedValue(min=2, max=8)
     apply_bounded_instruction(target, source, InstructionType.EQUALS)
     self.assertEqual(target.min, 0)
     self.assertEqual(target.max, 1)
Ejemplo n.º 11
0
 def test_div(self):
     target = BoundedValue(min=8, max=16)
     source = BoundedValue(min=2, max=4)
     apply_bounded_instruction(target, source, InstructionType.DIV)
     self.assertEqual(target.min, 2)
     self.assertEqual(target.max, 8)