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
105 lines (102 loc) · 2.77 KB
/
PasswordTest.cpp
File metadata and controls
105 lines (102 loc) · 2.77 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
/**
* 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 'count_leading_characters' function
TEST(PasswordTest, count_leading_characters__single_char)
{
Password my_password;
ASSERT_EQ(1, my_password.count_leading_characters("Z"));
}
TEST(PasswordTest, count_leading_characters__mixed_char)
{
Password my_password;
ASSERT_EQ(2, my_password.count_leading_characters("ZZz"));
}
TEST(PasswordTest, count_leading_characters__empty_char)
{
Password my_password;
ASSERT_EQ(0, my_password.count_leading_characters(""));
}
TEST(PasswordTest, count_leading_characters__dup_char)
{
Password my_password;
ASSERT_EQ(2, my_password.count_leading_characters("aabb"));
}
TEST(PasswordTest, count_leading_characters__mixed_dup_char_1)
{
Password my_password;
ASSERT_EQ(2, my_password.count_leading_characters("Aabb"));
}
TEST(PasswordTest, count_leading_characters__mixed_dup_char_2)
{
Password my_password;
ASSERT_EQ(2, my_password.count_leading_characters("aaBb"));
}
// test 'has_mixed_case' function
TEST(PasswordTest, has_mixed_case__mixed_chars_1)
{
Password my_password;
ASSERT_TRUE(my_password.has_mixed_case("Aabb"));
}
TEST(PasswordTest, has_mixed_case__mixed_chars_2)
{
Password my_password;
ASSERT_TRUE(my_password.has_mixed_case("aaBb"));
}
TEST(PasswordTest, has_mixed_case__lower_chars)
{
Password my_password;
EXPECT_FALSE(my_password.has_mixed_case("ab"));
}
TEST(PasswordTest, has_mixed_case__upper_chars)
{
Password my_password;
EXPECT_FALSE(my_password.has_mixed_case("AB"));
}
// test 'get_unique_chars'
TEST(PasswordTest, get_unique_chars__standard_test)
{
Password my_password;
string input = "Password#01";
ASSERT_EQ(10, my_password.get_unique_chars(input));
}
TEST(PasswordTest, get_unique_chars__upper_chars)
{
Password my_password;
string input = "ABC";
ASSERT_EQ(3, my_password.get_unique_chars(input));
}
TEST(PasswordTest, get_unique_chars__lower_chars)
{
Password my_password;
string input = "abc";
ASSERT_EQ(3, my_password.get_unique_chars(input));
}
TEST(PasswordTest, get_unique_chars__empty_char)
{
Password my_password;
string input = "";
ASSERT_EQ(0, my_password.get_unique_chars(input));
}
TEST(PasswordTest, get_unique_chars__single_dup_lower_char)
{
Password my_password;
string input = "aaa";
ASSERT_EQ(1, my_password.get_unique_chars(input));
}
TEST(PasswordTest, get_unique_chars__single_dup_upper_char)
{
Password my_password;
string input = "AAA";
ASSERT_EQ(1, my_password.get_unique_chars(input));
}