File tree 3 files changed +83
-0
lines changed
3 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+
3
+ project (Adaptor_test)
4
+
5
+ include_directories (${Boost_INCLUDE_DIRS} )
6
+
7
+ add_executable (${PROJECT_NAME} adaptorTest.cpp)
8
+
9
+ target_link_libraries (${PROJECT_NAME} PUBLIC
10
+ gtest_main
11
+ ${Boost_LIBRARIES}
12
+ )
13
+
14
+ add_test (
15
+ NAME ${PROJECT_NAME}
16
+ COMMAND ${PROJECT_NAME}
17
+ )
18
+ install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ../bin)
Original file line number Diff line number Diff line change
1
+ struct Square
2
+ {
3
+ int side{0 };
4
+
5
+ explicit Square (const int side)
6
+ : side(side)
7
+ {
8
+ }
9
+ };
10
+
11
+ struct Rectangle
12
+ {
13
+ virtual int width () const = 0;
14
+ virtual int height () const = 0;
15
+
16
+ int area () const
17
+ {
18
+ return width () * height ();
19
+ }
20
+ };
21
+
22
+ struct SquareToRectangleAdapter : Rectangle
23
+ {
24
+ SquareToRectangleAdapter (const Square &square)
25
+ : square(square) {}
26
+
27
+ int width () const override
28
+ {
29
+ return square.side ;
30
+ }
31
+
32
+ int height () const override
33
+ {
34
+ return square.side ;
35
+ }
36
+
37
+ const Square □
38
+ };
39
+
40
+ #include " gtest/gtest.h"
41
+
42
+ // #include "helpers/iohelper.h"
43
+
44
+ // #include "exercise.cpp"
45
+
46
+ namespace
47
+ {
48
+ class Evaluate : public testing ::Test
49
+ {
50
+ };
51
+
52
+ TEST_F (Evaluate, SimpleTest)
53
+ {
54
+ Square sq{11 };
55
+ SquareToRectangleAdapter adapter{sq};
56
+ ASSERT_EQ (121 , adapter.area ());
57
+ }
58
+ } // namespace
59
+
60
+ int main (int ac, char *av[])
61
+ {
62
+ testing::InitGoogleTest (&ac, av);
63
+ return RUN_ALL_TESTS ();
64
+ }
Original file line number Diff line number Diff line change @@ -20,4 +20,5 @@ if(Boost_FOUND)
20
20
add_subdirectory (ObjectPool)
21
21
add_subdirectory (RAII)
22
22
add_subdirectory (Decorator)
23
+ add_subdirectory (Adaptor)
23
24
endif ()
You can’t perform that action at this time.
0 commit comments