-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validation.cpp
More file actions
107 lines (87 loc) · 3.36 KB
/
test_validation.cpp
File metadata and controls
107 lines (87 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// main.cpp
#include <iostream>
#include <string>
#include "functions/validation.h"
int main() {
std::string email, number, ip, url, color, jsonStr, inputStr;
size_t minLength, maxLength;
// Test email validation
std::cout << "Enter an email address: ";
std::getline(std::cin, email);
if (isValidEmail(email)) {
std::cout << "The email address is valid." << std::endl;
} else {
std::cout << "The email address is invalid." << std::endl;
}
// Test number validation
std::cout << "Enter a number: ";
std::getline(std::cin, number);
if (isValidNumber(number)) {
std::cout << "The number is valid." << std::endl;
} else {
std::cout << "The number is invalid." << std::endl;
}
// Test IPv4 validation
std::cout << "Enter an IPv4 address: ";
std::getline(std::cin, ip);
if (isValidIPv4(ip)) {
std::cout << "The IPv4 address is valid." << std::endl;
} else {
std::cout << "The IPv4 address is invalid." << std::endl;
}
// Test URL validation
std::cout << "Enter a URL: ";
std::getline(std::cin, url);
if (isValidURL(url)) {
std::cout << "The URL is valid." << std::endl;
} else {
std::cout << "The URL is invalid." << std::endl;
}
// Test hexadecimal color validation
std::cout << "Enter a hexadecimal color value: ";
std::getline(std::cin, color);
if (isValidHexColor(color)) {
std::cout << "The hexadecimal color value is valid." << std::endl;
} else {
std::cout << "The hexadecimal color value is invalid." << std::endl;
}
// Test JSON validation
std::cout << "Enter a JSON string: ";
std::getline(std::cin, jsonStr);
if (isValidJSON(jsonStr)) {
std::cout << "The JSON string is valid." << std::endl;
} else {
std::cout << "The JSON string is invalid." << std::endl;
}
// Test minimum length validation
std::cout << "Enter a string to check its minimum length: ";
std::getline(std::cin, inputStr);
std::cout << "Enter the minimum required length: ";
std::cin >> minLength;
std::cin.ignore(); // Ignore the newline character left in the input buffer
if (isValidMinLength(inputStr, minLength)) {
std::cout << "The string meets the minimum length requirement." << std::endl;
} else {
std::cout << "The string does not meet the minimum length requirement." << std::endl;
}
// Test maximum length validation
std::cout << "Enter a string to check its maximum length: ";
std::getline(std::cin, inputStr);
std::cout << "Enter the maximum allowed length: ";
std::cin >> maxLength;
std::cin.ignore(); // Ignore the newline character left in the input buffer
if (isValidMaxLength(inputStr, maxLength)) {
std::cout << "The string meets the maximum length requirement." << std::endl;
} else {
std::cout << "The string does not meet the maximum length requirement." << std::endl;
}
// Test alphabetic validation
std::cout << "Enter a string to check if it contains only alphabetic characters: ";
std::getline(std::cin, inputStr);
if (isValidAlphabet(inputStr)) {
std::cout << "The string contains only alphabetic characters." << std::endl;
} else {
std::cout << "The string contains non-alphabetic characters." << std::endl;
}
return 0;
}