You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static void assert_print_number(const char expected, double input)
{
/ In MinGW or visual studio(before 2015),the exponten is represented using three digits,like:"1e-009","1e 017"
* remove extra "0" to output "1e-09" or "1e 17",which makes testcase PASS */
// have bug, sizeof(new_buffer) should be strlen(new_buffer)
for(i = 0;i <sizeof(new_buffer);i )
{
if(i >3 && new_buffer[i] =='0') // if input is 1e-101, new_buffer will be "1e-11", it's error
{
if((new_buffer[i-3] =='e' && new_buffer[i-2] == '-' && new_buffer[i] =='0') ||(new_buffer[i-2] =='e' && new_buffer[i-1] ==' '))
{
while(new_buffer[i] !='\0')
{
new_buffer[i] = new_buffer[i 1];
i ;
}
}
}
}
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, buffer.buffer, "Printed number is not as expected.");
}
The text was updated successfully, but these errors were encountered:
you are right, but it's not a bug of cJSON itself, actually we shouldn't modify the output of the test API in test file, see #327 . However, some exponent(1e09, 1e17) has different outputs in different environments, which will always fail in some environments.
I think it is necessary to change a test method.
On "print_number.c" file, add three test cass. They fail to run. My IDE is visual studio 2017.
static void print_number_should_print_positive_reals(void)
{
assert_print_number("0.123", 0.123);
assert_print_number("1e-09", 10e-10);
assert_print_number("1000000000000", 10e11);
assert_print_number("1.23e 129", 123e 127);
assert_print_number("1.23e-126", 123e-128);
assert_print_number("3.1415926535897931", 3.1415926535897931);
}
static void assert_print_number(const char expected, double input)
{
/ In MinGW or visual studio(before 2015),the exponten is represented using three digits,like:"1e-009","1e 017"
* remove extra "0" to output "1e-09" or "1e 17",which makes testcase PASS */
// have bug, sizeof(new_buffer) should be strlen(new_buffer)
for(i = 0;i <sizeof(new_buffer);i )
{
if(i >3 && new_buffer[i] =='0') // if input is 1e-101, new_buffer will be "1e-11", it's error
{
if((new_buffer[i-3] =='e' && new_buffer[i-2] == '-' && new_buffer[i] =='0') ||(new_buffer[i-2] =='e' && new_buffer[i-1] ==' '))
{
while(new_buffer[i] !='\0')
{
new_buffer[i] = new_buffer[i 1];
i ;
}
}
}
}
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, buffer.buffer, "Printed number is not as expected.");
}
The text was updated successfully, but these errors were encountered: