Skip to content

Commit

Permalink
testing array longers than 101 (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelarguedas authored Aug 10, 2017
1 parent 3780b3c commit 21cc532
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions test_communication/test/message_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ get_messages_dynamic_array_primitives()
{
auto msg = std::make_shared<test_communication::msg::DynamicArrayPrimitives>();
// check sequences with more then 100 elements
const size_t size = 101;
const size_t size = 1000;
msg->bool_values.resize(size);
msg->byte_values.resize(size);
msg->char_values.resize(size);
Expand All @@ -254,7 +254,8 @@ get_messages_dynamic_array_primitives()
for (size_t i = 0; i < size; ++i) {
msg->bool_values[i] = (i % 2 != 0) ? true : false;
msg->byte_values[i] = static_cast<uint8_t>(i);
msg->char_values[i] = static_cast<char>(i);
// TODO(mikaelarguedas) only ascii chars supported across languages
msg->char_values[i] = static_cast<char>(i % (1 << 7));
msg->float32_values[i] = 1.125f * i;
msg->float64_values[i] = 1.125 * i;
msg->int8_values[i] = static_cast<int8_t>(i);
Expand Down
31 changes: 20 additions & 11 deletions test_communication/test/message_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
from test_communication.msg import StaticArrayPrimitives


def int_from_uint(value, nbits):
value = value % (1 << nbits)
if value >= (1 << (nbits - 1)):
value = value - (1 << nbits)
return value


def get_msg_builtins():
msg = Builtins()
msg.duration_value.sec = -1234567890
Expand Down Expand Up @@ -229,21 +236,23 @@ def get_msg_dynamic_array_primitives():
msg.check = 2
msgs.append(msg)

size = 101
size = 1000

msg = DynamicArrayPrimitives()
msg.bool_values = [i % 2 != 0 for i in range(size)]
msg.byte_values = [bytes([i]) for i in range(size)]
msg.char_values = [chr(i) for i in range(size)]
msg.byte_values = [bytes([i % (1 << 8)]) for i in range(size)]
# TODO(mikaelarguedas) only ascii chars supported across languages
msg.char_values = [chr(i % (1 << 7)) for i in range(size)]
msg.float32_values = [float(1.125 * i) for i in range(size)]
msg.float64_values = [1.125 * i for i in range(size)]
msg.int8_values = [i for i in range(size)]
msg.uint8_values = [i for i in range(size)]
msg.int16_values = [i for i in range(size)]
msg.uint16_values = [i for i in range(size)]
msg.int32_values = [i for i in range(size)]
msg.uint32_values = [i for i in range(size)]
msg.int64_values = [i for i in range(size)]
msg.uint64_values = [i for i in range(size)]
msg.int8_values = [int_from_uint(i, 8) for i in range(size)]
msg.uint8_values = [i % (1 << 8) for i in range(size)]
msg.int16_values = [int_from_uint(i, 16) for i in range(size)]
msg.uint16_values = [i % (1 << 16) for i in range(size)]
msg.int32_values = [int_from_uint(i, 32) for i in range(size)]
msg.uint32_values = [i % (1 << 32) for i in range(size)]
msg.int64_values = [int_from_uint(i, 64) for i in range(size)]
msg.uint64_values = [i % (1 << 64) for i in range(size)]
msg.string_values = [str(i) for i in range(size)]
msg.check = 3
msgs.append(msg)
Expand Down

0 comments on commit 21cc532

Please sign in to comment.