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.4 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_getd_WithMin(void) {
  50. int min = 10;
  51. char *input[] = {"sdf", "4", "10000000", NULL};
  52. fakeInput = input;
  53. TEST_ASSERT_EQUAL_INT64(10000000, getd("", &min, NULL));
  54. }
  55. void test_getd_WithMax(void) {
  56. int max = 1000;
  57. char *input[] = {"sdf", "4000", "10000000", "-200", NULL};
  58. fakeInput = input;
  59. TEST_ASSERT_EQUAL_INT64(-200, getd("", NULL, &max));
  60. }
  61. void test_getld_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_INT64(11001100, getld("", &min, &max));
  67. }
  68. void test_getlld_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_INT64(11001100, getlld("", &min, &max));
  74. }
  75. void test_gethu_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_UINT64(50, gethu("", &min, &max));
  81. }
  82. void test_getu_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_UINT64(1167, getu("", &min, &max));
  88. }
  89. void test_getlu_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_UINT64(11001100, getlu("", &min, &max));
  95. }
  96. void test_getllu_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_UINT64(11001100, getllu("", &min, &max));
  102. }