|
25 | 25 |
|
26 | 26 | #include "../headers/koan05_pointers.hpp"
|
27 | 27 |
|
28 |
| -void Koan05_pointers::a_sample_koan() |
| 28 | +void Koan05_pointers::they_are_just_variables() |
29 | 29 | {
|
30 |
| - bool test = false; |
31 |
| - ASSERT_EQUAL( test, true ); |
| 30 | + int an_int = 42; |
| 31 | + int *pointer_to_an_int = &an_int; |
| 32 | + ASSERT_EQUAL( *pointer_to_an_int, FILL_THE_NUMBER_IN ); |
| 33 | + ASSERT_EQUAL( pointer_to_an_int, THIS_IS_NOT_NULL ); |
| 34 | +} |
| 35 | + |
| 36 | +void Koan05_pointers::they_are_really_just_variables() |
| 37 | +{ |
| 38 | + int an_int = 42; |
| 39 | + int another_int = 21; |
| 40 | + int *pointer_to_an_int = &an_int; |
| 41 | + ASSERT_EQUAL( *pointer_to_an_int, FILL_THE_NUMBER_IN ); |
| 42 | + ASSERT_EQUAL( pointer_to_an_int, THIS_IS_NOT_NULL ); |
| 43 | + pointer_to_an_int = &another_int; |
| 44 | + ASSERT_EQUAL( *pointer_to_an_int, FILL_THE_NUMBER_IN ); |
| 45 | + ASSERT_EQUAL( pointer_to_an_int, THIS_IS_NOT_NULL ); |
| 46 | +} |
| 47 | + |
| 48 | +void Koan05_pointers::they_have_power() |
| 49 | +{ |
| 50 | + int an_int = 42; |
| 51 | + int *powerful_pointer = &an_int; |
| 52 | + ASSERT_EQUAL( *powerful_pointer, FILL_THE_NUMBER_IN ); |
| 53 | + ASSERT_EQUAL( powerful_pointer, THIS_IS_NOT_NULL ); |
| 54 | + *powerful_pointer = 21; |
| 55 | + ASSERT_EQUAL( an_int, FILL_THE_NUMBER_IN ); |
| 56 | + ASSERT_EQUAL( powerful_pointer, THIS_IS_NOT_NULL ); |
| 57 | +} |
| 58 | + |
| 59 | +void Koan05_pointers::they_are_not_almighty() |
| 60 | +{ |
| 61 | + const int an_int = 42; |
| 62 | + const int *wannabe_powerful = &an_int; |
| 63 | + ASSERT_EQUAL( *wannabe_powerful, FILL_THE_NUMBER_IN ); |
| 64 | + ASSERT_EQUAL( wannabe_powerful, THIS_IS_NOT_NULL ); |
| 65 | + // Will this work? Think about it! |
| 66 | + // What do you need to change to make it work? |
| 67 | +// *wannabe_powerful = 21; |
| 68 | + ASSERT_EQUAL( an_int, FILL_THE_NUMBER_IN ); |
| 69 | + ASSERT_EQUAL( wannabe_powerful, THIS_IS_NOT_NULL ); |
32 | 70 | }
|
33 | 71 |
|
34 | 72 | // EOF
|
0 commit comments