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.

116 lines
3.5 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_usergetd_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_INT(1167, usergetd("", &min, &max));
  48. }
  49. void test_usergetd_WithMin(void) {
  50. int min = 10;
  51. char *input[] = {"sdf", "4", "10000000", NULL};
  52. fakeInput = input;
  53. TEST_ASSERT_EQUAL_INT(10000000, usergetd("", &min, NULL));
  54. }
  55. void test_usergetd_WithMax(void) {
  56. int max = 1000;
  57. char *input[] = {"sdf", "4000", "10000000", "-200", NULL};
  58. fakeInput = input;
  59. TEST_ASSERT_EQUAL_INT(-200, usergetd("", NULL, &max));
  60. }
  61. void test_usergetld_WithMinAndMax(void) {
  62. long min = -100;
  63. long max = 100000000;
  64. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  65. fakeInput = input;
  66. TEST_ASSERT_EQUAL_INT(11001100, usergetld("", &min, &max));
  67. }
  68. void test_usergetlld_WithMinAndMax(void) {
  69. long long min = -100;
  70. long long max = 100000000;
  71. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  72. fakeInput = input;
  73. TEST_ASSERT_EQUAL_INT(11001100, usergetlld("", &min, &max));
  74. }
  75. void test_usergethu_WithMinAndMax(void) {
  76. unsigned short min = 10;
  77. unsigned short max = 100;
  78. char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
  79. fakeInput = input;
  80. TEST_ASSERT_EQUAL_UINT(50, usergethu("", &min, &max));
  81. }
  82. void test_usergetu_WithMinAndMax(void) {
  83. unsigned int min = 10;
  84. unsigned int max = 100000;
  85. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  86. fakeInput = input;
  87. TEST_ASSERT_EQUAL_UINT(1167, usergetu("", &min, &max));
  88. }
  89. void test_usergetlu_WithMinAndMax(void) {
  90. unsigned long min = 100;
  91. unsigned long max = 100000000;
  92. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  93. fakeInput = input;
  94. TEST_ASSERT_EQUAL_UINT(11001100, usergetlu("", &min, &max));
  95. }
  96. void test_usergetllu_WithMinAndMax(void) {
  97. unsigned long long min = 100;
  98. unsigned long long max = 100000000;
  99. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  100. fakeInput = input;
  101. TEST_ASSERT_EQUAL_UINT(11001100, usergetllu("", &min, &max));
  102. }