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.

123 lines
3.7 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_usergets_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 = usergets("", &minLength, &maxLength);
  13. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  14. }
  15. void test_usergets_WithMinLength(void) {
  16. unsigned long minLength = 3;
  17. char *input[] = {"", "ei", "e", "dddd", NULL};
  18. fakeInput = input;
  19. char *actual = usergets("", &minLength, NULL);
  20. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  21. }
  22. void test_usergets_WithMaxLength(void) {
  23. unsigned long maxLength = 6;
  24. char *input[] = {"dfdfdfdf", "dddd", NULL};
  25. fakeInput = input;
  26. char *actual = usergets("", NULL, &maxLength);
  27. TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
  28. }
  29. void test_usergets_WithAnyLength(void) {
  30. char *input[] = {"dfdfdfdf", NULL};
  31. fakeInput = input;
  32. char *actual = usergets("", NULL, NULL);
  33. TEST_ASSERT_EQUAL_CHAR_ARRAY("dfdfdfdf", actual, strlen(actual));
  34. }
  35. void test_usergethd_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_INT(50, usergethd("", &min, &max));
  41. }
  42. void test_usergethd_WithMin(void) {
  43. short min = 13;
  44. char *input[] = {"sdf", "1", "100000", "6000", NULL};
  45. fakeInput = input;
  46. TEST_ASSERT_EQUAL_INT(6000, usergethd("", &min, NULL));
  47. }
  48. void test_usergetd_WithMinAndMax(void) {
  49. int min = 10;
  50. int max = 100000;
  51. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  52. fakeInput = input;
  53. TEST_ASSERT_EQUAL_INT(1167, usergetd("", &min, &max));
  54. }
  55. void test_usergetd_WithMin(void) {
  56. int min = 10;
  57. char *input[] = {"sdf", "4", "10000000", NULL};
  58. fakeInput = input;
  59. TEST_ASSERT_EQUAL_INT(10000000, usergetd("", &min, NULL));
  60. }
  61. void test_usergetd_WithMax(void) {
  62. int max = 1000;
  63. char *input[] = {"sdf", "4000", "10000000", "-200", NULL};
  64. fakeInput = input;
  65. TEST_ASSERT_EQUAL_INT(-200, usergetd("", NULL, &max));
  66. }
  67. void test_usergetld_WithMinAndMax(void) {
  68. long min = -100;
  69. long max = 100000000;
  70. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  71. fakeInput = input;
  72. TEST_ASSERT_EQUAL_INT(11001100, usergetld("", &min, &max));
  73. }
  74. void test_usergetlld_WithMinAndMax(void) {
  75. long long min = -100;
  76. long long max = 100000000;
  77. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  78. fakeInput = input;
  79. TEST_ASSERT_EQUAL_INT(11001100, usergetlld("", &min, &max));
  80. }
  81. void test_usergethu_WithMinAndMax(void) {
  82. unsigned short min = 10;
  83. unsigned short max = 100;
  84. char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
  85. fakeInput = input;
  86. TEST_ASSERT_EQUAL_UINT(50, usergethu("", &min, &max));
  87. }
  88. void test_usergetu_WithMinAndMax(void) {
  89. unsigned int min = 10;
  90. unsigned int max = 100000;
  91. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  92. fakeInput = input;
  93. TEST_ASSERT_EQUAL_UINT(1167, usergetu("", &min, &max));
  94. }
  95. void test_usergetlu_WithMinAndMax(void) {
  96. unsigned long min = 100;
  97. unsigned long max = 100000000;
  98. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  99. fakeInput = input;
  100. TEST_ASSERT_EQUAL_UINT(11001100, usergetlu("", &min, &max));
  101. }
  102. void test_usergetllu_WithMinAndMax(void) {
  103. unsigned long long min = 100;
  104. unsigned long long max = 100000000;
  105. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  106. fakeInput = input;
  107. TEST_ASSERT_EQUAL_UINT(11001100, usergetllu("", &min, &max));
  108. }