forked from ChicoState/UnitTestPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordTest.cpp
More file actions
146 lines (117 loc) · 3 KB
/
PasswordTest.cpp
File metadata and controls
146 lines (117 loc) · 3 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Unit Tests for Password class
**/
#include <gtest/gtest.h>
#include "Password.h"
class PasswordTest : public ::testing::Test
{
protected:
PasswordTest(){} //constructor runs before each test
virtual ~PasswordTest(){} //destructor cleans up after tests
virtual void SetUp(){} //sets up before each test (after constructor)
virtual void TearDown(){} //clean up after each test, (before destructor)
};
TEST(PasswordTest, single_letter_password)
{
Password my_password;
int actual = my_password.count_leading_characters("Z");
ASSERT_EQ(1, actual);
}
TEST(PasswordTest, multi_run_password)
{
Password my_password;
int actual = my_password.count_leading_characters("aaaddd");
ASSERT_EQ(3, actual);
}
TEST(PasswordTest, case_check_password)
{
Password my_password;
int actual = my_password.count_leading_characters("JJjjj");
ASSERT_EQ(2, actual);
}
TEST(PasswordTest, all_same_password)
{
Password my_password;
int actual = my_password.count_leading_characters("aaaaa");
ASSERT_EQ(5, actual);
}
TEST(PasswordTest, late_run_password)
{
Password my_password;
int actual = my_password.count_leading_characters("haiiiiiiiii");
ASSERT_EQ(1, actual);
}
TEST(PasswordTest, empty_string)
{
Password my_password;
int actual = my_password.count_leading_characters("");
ASSERT_EQ(0, actual);
}
TEST(PasswordTest, special_character_password)
{
Password my_password;
int actual = my_password.count_leading_characters("$$$#@!!@#$$$");
ASSERT_EQ(3, actual);
}
TEST(PasswordTest, null_string_password)
{
Password my_password;
int actual = my_password.count_leading_characters(NULL);
ASSERT_EQ(0, actual);
}
// MIXED CASE TESTS
TEST(PasswordTest, mixed_single_letter_password)
{
Password my_password;
int actual = my_password.has_mixed_case("Z");
ASSERT_FALSE(actual);
}
TEST(PasswordTest, mixed_character_password)
{
Password my_password;
int actual = my_password.has_mixed_case("XyZ");
ASSERT_TRUE(actual);
}
TEST(PasswordTest, mixed_character_long_password)
{
Password my_password;
int actual = my_password.has_mixed_case("XyZzzzzabcDDDDD");
ASSERT_TRUE(actual);
}
TEST(PasswordTest, no_mixed_character_password)
{
Password my_password;
int actual = my_password.has_mixed_case("password");
ASSERT_FALSE(actual);
}
TEST(PasswordTest, oops_just_numbers_password)
{
Password my_password;
int actual = my_password.has_mixed_case("1235634787964");
ASSERT_FALSE(actual);
}
// UNIQ CHARACTER TESTS
TEST(PasswordTest, simple_unique_characters)
{
Password my_password;
int actual = my_password.unique_characters("abcde");
ASSERT_EQ(5, actual);
}
TEST(PasswordTest, complex_unique_characters)
{
Password my_password;
int actual = my_password.unique_characters("aaAAbCCCbbbaaCD");
ASSERT_EQ(5, actual);
}
TEST(PasswordTest, special_characters_and_numbers)
{
Password my_password;
int actual = my_password.unique_characters("password13$&");
ASSERT_EQ(11, actual);
}
TEST(PasswordTest, character_run)
{
Password my_password;
int actual = my_password.unique_characters("aaaaaaaaaaaaaa");
ASSERT_EQ(1, actual);
}