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.

87 lines
2.6 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_gethd_WithMinAndMax(void) {
  23. short min = 10;
  24. short max = 100;
  25. char *input[] = {"sdf", "1", "101", "50", NULL};
  26. fakeInput = input;
  27. TEST_ASSERT_EQUAL_INT64(50, gethd("", &min, &max));
  28. }
  29. void test_getd_WithMinAndMax(void) {
  30. int min = 10;
  31. int max = 100000;
  32. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  33. fakeInput = input;
  34. TEST_ASSERT_EQUAL_INT64(1167, getd("", &min, &max));
  35. }
  36. void test_getld_WithMinAndMax(void) {
  37. long min = -100;
  38. long max = 100000000;
  39. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  40. fakeInput = input;
  41. TEST_ASSERT_EQUAL_INT64(11001100, getld("", &min, &max));
  42. }
  43. void test_getlld_WithMinAndMax(void) {
  44. long long min = -100;
  45. long long max = 100000000;
  46. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  47. fakeInput = input;
  48. TEST_ASSERT_EQUAL_INT64(11001100, getlld("", &min, &max));
  49. }
  50. void test_gethu_WithMinAndMax(void) {
  51. unsigned short min = 10;
  52. unsigned short max = 100;
  53. char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
  54. fakeInput = input;
  55. TEST_ASSERT_EQUAL_UINT64(50, gethu("", &min, &max));
  56. }
  57. void test_getu_WithMinAndMax(void) {
  58. unsigned int min = 10;
  59. unsigned int max = 100000;
  60. char *input[] = {"sdf", "4", "10000000", "1167", NULL};
  61. fakeInput = input;
  62. TEST_ASSERT_EQUAL_UINT64(1167, getu("", &min, &max));
  63. }
  64. void test_getlu_WithMinAndMax(void) {
  65. unsigned long min = 100;
  66. unsigned long max = 100000000;
  67. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  68. fakeInput = input;
  69. TEST_ASSERT_EQUAL_UINT64(11001100, getlu("", &min, &max));
  70. }
  71. void test_getllu_WithMinAndMax(void) {
  72. unsigned long long min = 100;
  73. unsigned long long max = 100000000;
  74. char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
  75. fakeInput = input;
  76. TEST_ASSERT_EQUAL_UINT64(11001100, getllu("", &min, &max));
  77. }