test/src/scale/scale_optional_test.cpp
TEST(Scale, encodeOptional) {
  // most simple case
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint8_t>{boost::none}));
    ASSERT_EQ(s.data(), (ByteArray{0}));
  }

  // encode existing uint8_t
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint8_t>{1}));
    ASSERT_EQ(s.data(), (ByteArray{1, 1}));
  }

  // encode negative int8_t
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<int8_t>{-1}));
    ASSERT_EQ(s.data(), (ByteArray{1, 255}));
  }

  // encode non-existing uint16_t
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint16_t>{boost::none}));
    ASSERT_EQ(s.data(), (ByteArray{0}));
  }

  // encode existing uint16_t
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint16_t>{511}));
    ASSERT_EQ(s.data(), (ByteArray{1, 255, 1}));
  }

  // encode existing uint32_t
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint32_t>{67305985}));
    ASSERT_EQ(s.data(), (ByteArray{1, 1, 2, 3, 4}));
  }
}
// TODO(yuraz): PRE-119 refactor to parameterized tests
/**
 * @given variety of optional values
 * @when encodeOptional function is applied
 * @then expected result obtained
 */
PRE-119 refactor to parameterized tests
@given variety of optional values
@when encodeOptional function is applied
@then expected result obtained
PRE - 119 refactor to parameterized tests @given variety of optional values @when encodeOptional function is applied @then expected result obtained
TEST(Scale, encodeOptional) {
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint8_t>{boost::none}));
    ASSERT_EQ(s.data(), (ByteArray{0}));
  }
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint8_t>{1}));
    ASSERT_EQ(s.data(), (ByteArray{1, 1}));
  }
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<int8_t>{-1}));
    ASSERT_EQ(s.data(), (ByteArray{1, 255}));
  }
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint16_t>{boost::none}));
    ASSERT_EQ(s.data(), (ByteArray{0}));
  }
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint16_t>{511}));
    ASSERT_EQ(s.data(), (ByteArray{1, 255, 1}));
  }
  {
    ScaleEncoderStream s;
    ASSERT_NO_THROW((s << boost::optional<uint32_t>{67305985}));
    ASSERT_EQ(s.data(), (ByteArray{1, 1, 2, 3, 4}));
  }
}
TEST ( Scale , encodeOptional ) { { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < uint8_t > { boost :: none } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 0 } ) ) ; } { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < uint8_t > { 1 } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 1 , 1 } ) ) ; } { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < int8_t > { -1 } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 1 , 255 } ) ) ; } { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < uint16_t > { boost :: none } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 0 } ) ) ; } { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < uint16_t > { 511 } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 1 , 255 , 1 } ) ) ; } { ScaleEncoderStream s ; ASSERT_NO_THROW ( ( s << boost :: optional < uint32_t > { 67305985 } ) ) ; ASSERT_EQ ( s . data ( ) , ( ByteArray { 1 , 1 , 2 , 3 , 4 } ) ) ; } }
TODO(yuraz): PRE-119 refactor to parameterized tests
 @given variety of optional values
 @when encodeOptional function is applied
 @then expected result obtained
TODO ( yuraz ) : PRE - 119 refactor to parameterized tests @given variety of optional values @when encodeOptional function is applied @then expected result obtained
// most simple case // encode existing uint8_t // encode negative int8_t // encode non-existing uint16_t // encode existing uint16_t // encode existing uint32_t