forked from ChicoState/UnitTestPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword.cpp.gcov
More file actions
59 lines (59 loc) · 2.12 KB
/
Copy pathPassword.cpp.gcov
File metadata and controls
59 lines (59 loc) · 2.12 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
-: 0:Source:Password.cpp
-: 0:Graph:Password.gcno
-: 0:Data:Password.gcda
-: 0:Runs:1
-: 1:#include "Password.h"
-: 2:#include <cctype>
-: 3:#include <set>
-: 4:#include <string>
-: 5:
-: 6:using std::string;
-: 7:
-: 8:/*
-: 9: The function receives a string counts how many times the same character
-: 10: occurs at the beginning of the string, before any other characters (or the
-: 11: end of the string). The function is case-sensitive so 'Z' is different than
-: 12: 'z' and any ASCII characters are allowed.
-: 13:*/
#####: 14:int Password::count_leading_characters(string phrase){
#####: 15: if (phrase.empty())
-: 16: {
#####: 17: return 0;
-: 18: }
-: 19:
#####: 20: int repetition = 1;
#####: 21: string::size_type index = 0;
#####: 22: while( index < phrase.length()-1 && phrase[index] == phrase[index+1] ){
#####: 23: repetition++;
#####: 24: index++;
-: 25: }
#####: 26: return repetition;
-: 27:}
-: 28:
14: 29:unsigned int Password::unique_characters(string str)
-: 30:{
14: 31: std::set<char> seen;
48: 32: for (char ch : str)
-: 33: {
34: 34: seen.insert(ch);
-: 35: }
28: 36: return seen.size();
14: 37:}
-: 38:
#####: 39:bool Password::has_mixed_case(string str)
-: 40:{
#####: 41: bool has_lower = false;
#####: 42: bool has_upper = false;
#####: 43: for (char ch : str)
-: 44: {
#####: 45: if (std::islower(static_cast<unsigned char>(ch)))
-: 46: {
#####: 47: has_lower = true;
-: 48: }
#####: 49: else if (std::isupper(static_cast<unsigned char>(ch)))
-: 50: {
#####: 51: has_upper = true;
-: 52: }
-: 53: }
#####: 54: return has_lower && has_upper;
-: 55:}