|
|
@@ -19,7 +19,7 @@ struct MockRandomImpl : public engine::detail::random_impl {
|
|
|
double inclusive(double, double) { throw; }
|
|
|
};
|
|
|
|
|
|
-class RollTest : public ::testing::Test {
|
|
|
+class RollerTest : public ::testing::Test {
|
|
|
protected:
|
|
|
void SetUp() override {
|
|
|
pRandom = std::make_shared<MockRandomImpl>();
|
|
|
@@ -35,12 +35,12 @@ protected:
|
|
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
-TEST_F(RollTest, CanConstructNoThrow) {
|
|
|
+TEST_F(RollerTest, CanConstructNoThrow) {
|
|
|
EXPECT_NO_THROW(dice::roller{});
|
|
|
EXPECT_NO_THROW(dice::roller{pRandom});
|
|
|
}
|
|
|
|
|
|
-TEST_F(RollTest, RollsOncePerDie) {
|
|
|
+TEST_F(RollerTest, RollsOncePerDie) {
|
|
|
dice::dice mydice{1, {{dice::sign::ZERO, 3, 4}}, {{dice::sign::PLUS, 1}}};
|
|
|
EXPECT_CALL(*pRandom, exclusive(4)).WillOnce(Return(2)).WillOnce(Return(1))
|
|
|
.WillOnce(Return(3));
|
|
|
@@ -51,7 +51,7 @@ TEST_F(RollTest, RollsOncePerDie) {
|
|
|
EXPECT_THAT(roll[0].sub_rolls[0].rolled, ElementsAre(3, 2, 4));
|
|
|
}
|
|
|
|
|
|
-TEST_F(RollTest, DoesNotRollForConstants) {
|
|
|
+TEST_F(RollerTest, DoesNotRollForConstants) {
|
|
|
dice::dice mydice{1, {}, {{dice::sign::PLUS, 1}}};
|
|
|
EXPECT_CALL(*pRandom, exclusive(_)).Times(0);
|
|
|
|
|
|
@@ -62,12 +62,35 @@ TEST_F(RollTest, DoesNotRollForConstants) {
|
|
|
EXPECT_THAT(roll[0].modifiers[0].value, Eq(1));
|
|
|
}
|
|
|
|
|
|
-TEST_F(RollTest, OperatorInSumsElements) {
|
|
|
- dice::dice mydice{1, {{dice::sign::ZERO, 3, 4}}, {{dice::sign::PLUS, 1}}};
|
|
|
+TEST_F(RollerTest, InjectsDCIntoRollObjects) {
|
|
|
+ using test = dice::difficulty_class::test;
|
|
|
+ dice::dice mydice{1, {{dice::sign::ZERO, 3, 4}},
|
|
|
+ {{dice::sign::PLUS, 1}}, {test::Less, 20}};
|
|
|
EXPECT_CALL(*pRandom, exclusive(4)).WillOnce(Return(2)).WillOnce(Return(1))
|
|
|
- .WillOnce(Return(3));
|
|
|
-
|
|
|
+ .WillOnce(Return(3));
|
|
|
+
|
|
|
auto roll = dice::roller{pRandom}(mydice);
|
|
|
+ EXPECT_THAT(roll, Each(Field(&dice::dice_roll::dc,
|
|
|
+ Field(&dice::difficulty_class::against, 20))));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DiceRollTest, OperatorIntSumsElements) {
|
|
|
+ dice::dice_roll const roll{
|
|
|
+ {{dice::sign::ZERO, {3, 2, 4}}},
|
|
|
+ {{dice::sign::PLUS, 1}}};
|
|
|
// 3 + 2 + 4 + 1 = 10
|
|
|
- EXPECT_THAT(int(roll[0]), Eq(10));
|
|
|
+ EXPECT_THAT(int(roll), Eq(10));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DiceRollTest, OperatorIntWithDCReturnsOneOrZero) {
|
|
|
+ using test = dice::difficulty_class::test;
|
|
|
+ dice::dice_roll roll{
|
|
|
+ {{dice::sign::ZERO, {3, 2, 4}}},
|
|
|
+ {{dice::sign::PLUS, 1}},
|
|
|
+ {test::Less, 10}
|
|
|
+ };
|
|
|
+
|
|
|
+ EXPECT_THAT(int(roll), Eq(0));
|
|
|
+ --roll.modifiers[0].value;
|
|
|
+ EXPECT_THAT(int(roll), Eq(1));
|
|
|
}
|