def test_mixed_operation(self):
        user = "******"
        spec = OperationSpec()
        operation_result = OperationResult(spec)

        roll_spec = RollSpec(modifier=5, operation="+")
        spec.add_part(roll_spec)
        roll_result = RollResult(roll_spec)
        roll_result.apply_modifier(5)
        operation_result.append_roll_result(roll_result)

        roll_spec_2 = RollSpec(dice_count=3, dice_sides=20, operation="-")
        spec.add_part(roll_spec_2)
        roll_result_2 = RollResult(roll_spec_2)
        roll_result_2.append_roll(1)
        roll_result_2.append_roll(2)
        roll_result_2.append_roll(3)
        operation_result.append_roll_result(roll_result_2)

        roll_spec_3 = RollSpec(modifier=2, operation="-")
        spec.add_part(roll_spec_3)
        roll_result_3 = RollResult(roll_spec_3)
        roll_result_3.apply_modifier(2)
        operation_result.append_roll_result(roll_result_3)

        writer = OperationOutputWriter()
        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: 5 - [1, 2, 3] - 2 Result: -3"
        self.assertEqual(expected_result, result)
    def test_multiply_with_addition_dice_operations(self):
        user = "******"
        spec = OperationSpec()
        roll_spec = RollSpec(dice_count=3, dice_sides=6, operation="+")
        spec.add_part(roll_spec)
        operation_result = OperationResult(spec)
        roll_result = RollResult(roll_spec)
        roll_result.append_roll(3)
        roll_result.append_roll(2)
        roll_result.append_roll(5)
        operation_result.append_roll_result(roll_result)

        roll_spec_2 = RollSpec(dice_count=3, dice_sides=20, operation="*")
        spec.add_part(roll_spec_2)
        roll_result_2 = RollResult(roll_spec_2)
        roll_result_2.append_roll(2)
        roll_result_2.append_roll(2)
        roll_result_2.append_roll(1)
        operation_result.append_roll_result(roll_result_2)

        roll_spec_3 = RollSpec(dice_count=0, dice_sides=0, modifier=3, operation="+")
        spec.add_part(roll_spec_3)
        roll_result_3 = RollResult(roll_spec_3)
        roll_result_3.apply_modifier(roll_spec_3.dice_modifier)
        operation_result.append_roll_result(roll_result_3)

        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: [3, 2, 5] * [2, 2, 1] + 3 Result: 53"
        self.assertEqual(expected_result, result)
    def test_targeted_multiple_operation(self):
        user = "******"
        spec = OperationSpec()
        roll_spec = RollSpec(dice_count=3, dice_sides=6, operation="+")
        spec.add_part(roll_spec)
        spec.target_number = 5
        operation_result = OperationResult(spec)
        roll_result = RollResult(roll_spec)
        roll_result.append_roll(1)
        roll_result.append_roll(2)
        roll_result.append_roll(3)
        operation_result.append_roll_result(roll_result)

        roll_spec_3 = RollSpec(modifier=2, operation="-")
        spec.add_part(roll_spec_3)
        roll_result_3 = RollResult(roll_spec_3)
        roll_result_3.apply_modifier(2)
        operation_result.append_roll_result(roll_result_3)

        operation_result.met_target = False
        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: [1, 2, 3] - 2 Result: 4 Target: 5 Failure"
        self.assertEqual(expected_result, result)
Beispiel #4
0
    def test_build_total_string_with_modifier(self):
        writer = StandardOutputWriter()
        roll_spec = RollSpec(dice_sides=10, dice_count=2, modifier=7)
        roll_result = RollResult(spec=roll_spec)
        roll_result.append_roll(5)
        roll_result.append_roll(4)
        roll_result.apply_modifier(7)

        result_string = writer.build_total_string(roll_result=roll_result)
        expected_result_string = "[5, 4] = 9 + 7"
        self.assertEqual(expected_result_string, result_string)
    def test_single_modifier_operations(self):
        user = "******"
        spec = OperationSpec()
        roll_spec = RollSpec(modifier=5, operation="+")
        spec.add_part(roll_spec)
        operation_result = OperationResult(spec)
        roll_result = RollResult(roll_spec)
        roll_result.apply_modifier(5)

        operation_result.append_roll_result(roll_result)
        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: 5 Result: 5"
        self.assertEqual(expected_result, result)
    def test_multiple_modifier_operations(self):
        user = "******"
        spec = OperationSpec()
        operation_result = OperationResult(spec)

        roll_spec = RollSpec(modifier=5, operation="+")
        spec.add_part(roll_spec)
        roll_result = RollResult(roll_spec)
        roll_result.apply_modifier(5)
        operation_result.append_roll_result(roll_result)

        roll_spec_2 = RollSpec(modifier=3, operation="-")
        spec.add_part(roll_spec_2)
        roll_result_2 = RollResult(roll_spec_2)
        roll_result_2.apply_modifier(3)
        operation_result.append_roll_result(roll_result_2)

        roll_spec_3 = RollSpec(modifier=2, operation="+")
        spec.add_part(roll_spec_3)
        roll_result_3 = RollResult(roll_spec_3)
        roll_result_3.apply_modifier(2)
        operation_result.append_roll_result(roll_result_3)

        writer = OperationOutputWriter()
        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: 5 - 3 + 2 Result: 4"
        self.assertEqual(expected_result, result)
    def test_divide_operator_operations(self):
        user = "******"
        spec = OperationSpec()
        roll_spec = RollSpec(dice_count=3, dice_sides=6, operation="+")
        spec.add_part(roll_spec)
        operation_result = OperationResult(spec)
        roll_result = RollResult(roll_spec)
        roll_result.append_roll(3)
        roll_result.append_roll(2)
        roll_result.append_roll(5)
        operation_result.append_roll_result(roll_result)

        roll_spec_3 = RollSpec(dice_count=0, dice_sides=0, modifier=2, operation="/")
        spec.add_part(roll_spec_3)
        roll_result_3 = RollResult(roll_spec_3)
        roll_result_3.apply_modifier(roll_spec_3.dice_modifier)
        operation_result.append_roll_result(roll_result_3)

        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: [3, 2, 5] / 2 Result: 5"
        self.assertEqual(expected_result, result)
Beispiel #8
0
 def test_apply_modifier_on_total(self):
     roll_result = RollResult(spec=RollSpec(dice_count=1, dice_sides=6))
     roll_result.total = 10
     roll_result.apply_modifier(7)
     self.assertEqual(17, roll_result.total)