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.
117 lines
3.4 KiB
117 lines
3.4 KiB
#include "unity.h"
|
|
#include "userinput.h"
|
|
#include "fakeinput.h"
|
|
#include <string.h>
|
|
|
|
void setUp(void){}
|
|
void tearDown(void){}
|
|
|
|
void test_gets_WithMinLengthAndMaxLength(void) {
|
|
unsigned long minLength = 3;
|
|
unsigned long maxLength = 10;
|
|
char *input[] = {"ei", "e", "sddfdfdfdfdf", "dddd", NULL};
|
|
fakeInput = input;
|
|
char *actual = gets("", &minLength, &maxLength);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
|
|
}
|
|
|
|
void test_gets_WithMin(void) {
|
|
unsigned long minLength = 3;
|
|
char *input[] = {"", "ei", "e", "dddd", NULL};
|
|
fakeInput = input;
|
|
char *actual = gets("", &minLength, NULL);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
|
|
}
|
|
|
|
void test_gets_WithMax(void) {
|
|
unsigned long maxLength = 6;
|
|
char *input[] = {"dfdfdfdf", "dddd", NULL};
|
|
fakeInput = input;
|
|
char *actual = gets("", NULL, &maxLength);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("dddd", actual, strlen(actual));
|
|
}
|
|
|
|
void test_gets_WithAnyLength(void) {
|
|
char *input[] = {"dfdfdfdf", NULL};
|
|
fakeInput = input;
|
|
char *actual = gets("", NULL, NULL);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("dfdfdfdf", actual, strlen(actual));
|
|
}
|
|
|
|
void test_gethd_WithMinAndMax(void) {
|
|
short min = 10;
|
|
short max = 100;
|
|
char *input[] = {"sdf", "1", "101", "50", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(50, gethd("", &min, &max));
|
|
}
|
|
|
|
void test_getd_WithMinAndMax(void) {
|
|
int min = 10;
|
|
int max = 100000;
|
|
char *input[] = {"sdf", "4", "10000000", "1167", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(1167, getd("", &min, &max));
|
|
}
|
|
|
|
void test_getd_WithMin(void) {
|
|
int min = 10;
|
|
char *input[] = {"sdf", "4", "10000000", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(10000000, getd("", &min, NULL));
|
|
}
|
|
|
|
void test_getd_WithMax(void) {
|
|
int max = 1000;
|
|
char *input[] = {"sdf", "4000", "10000000", "-200", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(-200, getd("", NULL, &max));
|
|
}
|
|
|
|
void test_getld_WithMinAndMax(void) {
|
|
long min = -100;
|
|
long max = 100000000;
|
|
char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(11001100, getld("", &min, &max));
|
|
}
|
|
|
|
void test_getlld_WithMinAndMax(void) {
|
|
long long min = -100;
|
|
long long max = 100000000;
|
|
char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_INT64(11001100, getlld("", &min, &max));
|
|
}
|
|
|
|
void test_gethu_WithMinAndMax(void) {
|
|
unsigned short min = 10;
|
|
unsigned short max = 100;
|
|
char *input[] = {"sdf", "-1", "1", "101", "50", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_UINT64(50, gethu("", &min, &max));
|
|
}
|
|
|
|
void test_getu_WithMinAndMax(void) {
|
|
unsigned int min = 10;
|
|
unsigned int max = 100000;
|
|
char *input[] = {"sdf", "4", "10000000", "1167", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_UINT64(1167, getu("", &min, &max));
|
|
}
|
|
|
|
void test_getlu_WithMinAndMax(void) {
|
|
unsigned long min = 100;
|
|
unsigned long max = 100000000;
|
|
char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_UINT64(11001100, getlu("", &min, &max));
|
|
}
|
|
|
|
void test_getllu_WithMinAndMax(void) {
|
|
unsigned long long min = 100;
|
|
unsigned long long max = 100000000;
|
|
char *input[] = {"sdf", "-400", "10000000000000", "11001100", NULL};
|
|
fakeInput = input;
|
|
TEST_ASSERT_EQUAL_UINT64(11001100, getllu("", &min, &max));
|
|
}
|