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)
Ejemplo n.º 2
0
    def test_build_total_string(self):
        writer = StandardOutputWriter()
        roll_spec = RollSpec(dice_sides=10, dice_count=2)
        roll_result = RollResult(spec=roll_spec)
        roll_result.append_roll(3)
        roll_result.append_roll(4)

        result_string = writer.build_total_string(roll_result=roll_result)
        expected_result_string = "[3, 4] = 7"
        self.assertEqual(expected_result_string, result_string)
Ejemplo n.º 3
0
    def test_write_output(self):
        writer = StandardOutputWriter()
        roll_spec = RollSpec(dice_sides=10, dice_count=2)
        roll_result = RollResult(spec=roll_spec)
        roll_result.append_roll(3)
        roll_result.append_roll(4)

        result_string = writer.write_output(roll_result=roll_result,
                                            user="******")
        expected_result_string = "tester Roll: [3, 4] = 7 Result: 7"
        self.assertEqual(expected_result_string, result_string)
Ejemplo n.º 4
0
    def test_build_result_string_missed_target(self):
        writer = TargetedOutputWriter()
        roll_spec = RollSpec(dice_sides=10, dice_count=2, target_number=5)
        roll_result = RollResult(spec=roll_spec)
        roll_result.append_roll(3)
        roll_result.append_roll(4)
        roll_result.met_target = False

        result_string = writer.build_result_string(roll_result=roll_result,
                                                   total_string="totalString",
                                                   user="******")
        expected_result_string = "tester Roll: totalString Total: 7 Target: 5 Result: Failed"
        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)
Ejemplo n.º 6
0
 def test_roll_dice_set_multiple_die_no_modifier(self, mock_generator):
     spec = RollSpec(dice_count=4, dice_sides=13)
     mock_generator.return_value = TestGenerator([1, 2, 3, 5])
     roller = StandardRoller()
     result = RollResult(spec=spec)
     roller.roll_dice_set(spec, result)
     self.assertEqual(result.total, 1 + 2 + 3 + 5)
Ejemplo n.º 7
0
 def test_append_roll(self):
     roll_result = RollResult(spec=RollSpec(dice_count=1, dice_sides=6))
     self.assertEqual([], roll_result.rolls)
     roll_result.append_roll(1)
     self.assertEqual([1], roll_result.rolls)
     roll_result.append_roll(2)
     self.assertEqual([1, 2], roll_result.rolls)
    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)
Ejemplo n.º 9
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_operation(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(1)
        roll_result.append_roll(2)
        roll_result.append_roll(3)
        operation_result.append_roll_result(roll_result)
        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: [1, 2, 3] Result: 6"
        self.assertEqual(expected_result, result)
    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_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_multiple_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(1)
        roll_result.append_roll(2)
        roll_result.append_roll(3)
        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(5)
        roll_result_2.append_roll(10)
        roll_result_2.append_roll(15)
        operation_result.append_roll_result(roll_result_2)
        writer = OperationOutputWriter()

        result = writer.write_output(operation_result, user)
        expected_result = "Test Roll: [1, 2, 3] + [5, 10, 15] Result: 36"
        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)
Ejemplo n.º 15
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)