You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. #include "unity.h"
  2. #include "StringManipulation.h"
  3. void test_to_string()
  4. {
  5. /*initializing test values*/
  6. char *result_1[] = {"0","1","2","3","4","5","6","7","8","9","10"};
  7. char *result_2[] = {"500","502","504","506","508","510","512","514","516","518"};
  8. char *result_3[] = {"1000","2000","3000","4000","5000","6000","7000","8000","9000","10000"};
  9. char *result_4[] = {"9999","8999","7999","6999","5999","4999","3999","2999","1999","999"};
  10. char *result_5[] = {"1000000","2000000","3000000","4000000","5000000","6000000","7000000",
  11. "8000000","9000000","10000000"};
  12. for(int i=0;i<=10;++i){
  13. printf("%s\n", to_string(i));
  14. TEST_ASSERT_EQUAL_STRING(result_1[i],to_string(i));
  15. }
  16. for(int i=0, j=500;i<10;++i,j+=2){
  17. printf("%s\n", to_string(j));
  18. TEST_ASSERT_EQUAL_STRING(result_2[i],to_string(j));
  19. }
  20. for(int i=0, j=1000;i<10;++i,j+=1000){
  21. printf("%s\n", to_string(j));
  22. TEST_ASSERT_EQUAL_STRING(result_3[i],to_string(j));
  23. }
  24. for(int i=0, j=9999;i<10;++i,j-=1000){
  25. printf("%s\n", to_string(j));
  26. TEST_ASSERT_EQUAL_STRING(result_4[i], to_string(j));
  27. }
  28. for(int i=0, j=1000000;i<10;++i,j+=1000000){
  29. printf("%s\n", to_string(j));
  30. TEST_ASSERT_EQUAL_STRING(result_5[i],to_string(j));
  31. }
  32. }