-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestOcrAccount.cpp
101 lines (85 loc) · 2.29 KB
/
TestOcrAccount.cpp
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
#include <gmock/gmock.h>
#include "OcrAccount.h"
using namespace testing;
using std::string;
using std::vector;
class TestOcrAccount: public Test
{
};
namespace
{
vector<string> account =
{
" _ _ _ _ _ _ _ ",
" | _| _||_||_ |_ ||_||_|",
" ||_ _| | _||_| ||_| _|"
};
vector<string> validAccount =
{
" _ _ _ _ _ _ _ _ ",
"| || || || || || || ||_ |",
"|_||_||_||_||_||_||_| _| |"
};
vector<string> invalidAccount =
{
" ",
" | | | | | | | | |",
" | | | | | | | | |",
};
vector<string> illegibleAccount =
{
" _ _ _ _ _ _ ",
" | _| _||_|| |_ ||_||_|",
" ||_ _| | _||_| ||_| _|"
};
vector<string> correctableAccount =
{
" _ _ _ _ _ _ _ ",
"|_||_|| ||_||_ | | | _ ",
" | _||_||_||_| | | | _|"
};
}
TEST_F(TestOcrAccount, CanDecodeAccountNumber)
{
OcrAccount ocrAccount(account);
EXPECT_EQ(string("123456789"), string(ocrAccount));
}
TEST_F(TestOcrAccount, CanDetectAccountNumberIsValid)
{
OcrAccount ocrAccount(validAccount);
EXPECT_TRUE(ocrAccount.isValid());
}
TEST_F(TestOcrAccount, CanDetectAccountNumberIsInvalid)
{
OcrAccount ocrAccount(invalidAccount);
EXPECT_FALSE(ocrAccount.isValid());
}
TEST_F(TestOcrAccount, CanDetectAccountNumberIsLegible)
{
OcrAccount ocrAccount(account);
EXPECT_TRUE(ocrAccount.isLegible());
}
TEST_F(TestOcrAccount, CanDetectAccountNumberIsIllegible)
{
OcrAccount ocrAccount(illegibleAccount);
EXPECT_FALSE(ocrAccount.isLegible());
}
TEST_F(TestOcrAccount, IllegibleAccountIsInvalid)
{
OcrAccount ocrAccount(illegibleAccount);
EXPECT_FALSE(ocrAccount.isValid());
}
TEST_F(TestOcrAccount, CanCorrectError)
{
OcrAccount ocrAccount(invalidAccount);
vector<string> corrections = ocrAccount.correctError();
vector<string> expected = { "711111111" };
EXPECT_EQ(corrections, expected);
}
TEST_F(TestOcrAccount, FiltersOutIllegibleAccountNumbers)
{
OcrAccount ocrAccount(correctableAccount);
vector<string> corrections = ocrAccount.correctError();
vector<string> expected = { "490867715" };
EXPECT_EQ(expected, corrections);
}