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.

102 lines
3.1 KiB

  1. #include "unity.h"
  2. #include "userinput.h"
  3. #include "fakeinput.h"
  4. #include <string.h>
  5. void setUp(void){}
  6. void tearDown(void){}
  7. void test_gets_WithMinLengthAndMaxLength(void) {
  8. unsigned long minLength = 3;
  9. unsigned long maxLength = 10;
  10. char *input[] = {"ei", "e", "sddfdfdfdfdf", "dddd", NULL};
  11. fakeInput = input;
  12. char *actual = gets("", &minLength, &maxLength);
  13. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  14. }
  15. void test_gets_WithMin(void) {
  16. unsigned long minLength = 3;
  17. char *input[] = {"", "ei", "e", "dddd", NULL};
  18. fakeInput = input;
  19. char *actual = gets("", &minLength, NULL);
  20. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  21. }
  22. void test_gets_WithMax(void) {
  23. unsigned long maxLength = 6;
  24. char *input[] = {"dfdfdfdf", "dddd", NULL};
  25. fakeInput = input;
  26. char *actual = gets("", NULL, &maxLength);
  27. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  28. }
  29. void test_gets_WithAnyLength(void) {
  30. char *input[] = {"dfdfdfdf", NULL};
  31. fakeInput = input;
  32. char *actual = gets("", NULL, NULL);
  33. TEST_ASSERT_EQUAL_CHAR_ARRAY("dfdfdfdf", actual, strlen(actual));
  34. }
  35. void test_gethd_WithMinAndMax(void) {
  36. short min = 10;
  37. short max = 100;
  38. char *input[] = {"sdf", "1", "101", "50", NULL};
  39. fakeInput = input;
  40. TEST_ASSERT_EQUAL_INT64(50, gethd("", &min, &max));
  41. }
  42. void test_getd_WithMinAndMax(void) {
  43. int min = 10;
  44. int max = 100000;
  45. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  46. fakeInput = input;
  47. TEST_ASSERT_EQUAL_INT64(1167, getd("", &min, &max));
  48. }
  49. void test_getld_WithMinAndMax(void) {
  50. long min = -100;
  51. long max = 100000000;
  52. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  53. fakeInput = input;
  54. TEST_ASSERT_EQUAL_INT64(11001100, getld("", &min, &max));
  55. }
  56. void test_getlld_WithMinAndMax(void) {
  57. long long min = -100;
  58. long long max = 100000000;
  59. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  60. fakeInput = input;
  61. TEST_ASSERT_EQUAL_INT64(11001100, getlld("", &min, &max));
  62. }
  63. void test_gethu_WithMinAndMax(void) {
  64. unsigned short min = 10;
  65. unsigned short max = 100;
  66. char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
  67. fakeInput = input;
  68. TEST_ASSERT_EQUAL_UINT64(50, gethu("", &min, &max));
  69. }
  70. void test_getu_WithMinAndMax(void) {
  71. unsigned int min = 10;
  72. unsigned int max = 100000;
  73. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  74. fakeInput = input;
  75. TEST_ASSERT_EQUAL_UINT64(1167, getu("", &min, &max));
  76. }
  77. void test_getlu_WithMinAndMax(void) {
  78. unsigned long min = 100;
  79. unsigned long max = 100000000;
  80. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  81. fakeInput = input;
  82. TEST_ASSERT_EQUAL_UINT64(11001100, getlu("", &min, &max));
  83. }
  84. void test_getllu_WithMinAndMax(void) {
  85. unsigned long long min = 100;
  86. unsigned long long max = 100000000;
  87. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  88. fakeInput = input;
  89. TEST_ASSERT_EQUAL_UINT64(11001100, getllu("", &min, &max));
  90. }