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.

109 lines
3.2 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_getld_WithMinAndMax(void) {
  56. long min = -100;
  57. long max = 100000000;
  58. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  59. fakeInput = input;
  60. TEST_ASSERT_EQUAL_INT64(11001100, getld("", &min, &max));
  61. }
  62. void test_getlld_WithMinAndMax(void) {
  63. long long min = -100;
  64. long long max = 100000000;
  65. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  66. fakeInput = input;
  67. TEST_ASSERT_EQUAL_INT64(11001100, getlld("", &min, &max));
  68. }
  69. void test_gethu_WithMinAndMax(void) {
  70. unsigned short min = 10;
  71. unsigned short max = 100;
  72. char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
  73. fakeInput = input;
  74. TEST_ASSERT_EQUAL_UINT64(50, gethu("", &min, &max));
  75. }
  76. void test_getu_WithMinAndMax(void) {
  77. unsigned int min = 10;
  78. unsigned int max = 100000;
  79. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  80. fakeInput = input;
  81. TEST_ASSERT_EQUAL_UINT64(1167, getu("", &min, &max));
  82. }
  83. void test_getlu_WithMinAndMax(void) {
  84. unsigned long min = 100;
  85. unsigned long max = 100000000;
  86. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  87. fakeInput = input;
  88. TEST_ASSERT_EQUAL_UINT64(11001100, getlu("", &min, &max));
  89. }
  90. void test_getllu_WithMinAndMax(void) {
  91. unsigned long long min = 100;
  92. unsigned long long max = 100000000;
  93. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  94. fakeInput = input;
  95. TEST_ASSERT_EQUAL_UINT64(11001100, getllu("", &min, &max));
  96. }