|
| 1 | +*"* use this source file for your ABAP unit test classes |
| 2 | +CLASS ltcl_resistor_color_duo DEFINITION FINAL FOR TESTING |
| 3 | + DURATION SHORT |
| 4 | + RISK LEVEL HARMLESS. |
| 5 | + |
| 6 | + PRIVATE SECTION. |
| 7 | + DATA cut TYPE REF TO zcl_resistor_color_duo. |
| 8 | + METHODS setup. |
| 9 | + METHODS: |
| 10 | + test_brown_and_black FOR TESTING, |
| 11 | + test_blue_and_grey FOR TESTING, |
| 12 | + test_yellow_and_violet FOR TESTING, |
| 13 | + test_white_and_red FOR TESTING, |
| 14 | + test_orange_and_orange FOR TESTING, |
| 15 | + test_ignore_additional_colors FOR TESTING, |
| 16 | + test_black_and_brown_one_digit FOR TESTING. |
| 17 | +ENDCLASS. |
| 18 | + |
| 19 | +CLASS ltcl_resistor_color_duo IMPLEMENTATION. |
| 20 | + |
| 21 | + METHOD setup. |
| 22 | + cut = NEW zcl_resistor_color_duo( ). |
| 23 | + ENDMETHOD. |
| 24 | + |
| 25 | + METHOD test_brown_and_black. |
| 26 | + DATA(colors) = VALUE string_table( ( `brown` ) ( `black` ) ). |
| 27 | + cl_abap_unit_assert=>assert_equals( |
| 28 | + act = cut->value( colors ) |
| 29 | + exp = 10 ). |
| 30 | + ENDMETHOD. |
| 31 | + |
| 32 | + METHOD test_blue_and_grey. |
| 33 | + DATA(colors) = VALUE string_table( ( `blue` ) ( `grey` ) ). |
| 34 | + cl_abap_unit_assert=>assert_equals( |
| 35 | + act = cut->value( colors ) |
| 36 | + exp = 68 ). |
| 37 | + ENDMETHOD. |
| 38 | + |
| 39 | + METHOD test_yellow_and_violet. |
| 40 | + DATA(colors) = VALUE string_table( ( `yellow` ) ( `violet` ) ). |
| 41 | + cl_abap_unit_assert=>assert_equals( |
| 42 | + act = cut->value( colors ) |
| 43 | + exp = 47 ). |
| 44 | + ENDMETHOD. |
| 45 | + |
| 46 | + METHOD test_white_and_red. |
| 47 | + DATA(colors) = VALUE string_table( ( `white` ) ( `red` ) ). |
| 48 | + cl_abap_unit_assert=>assert_equals( |
| 49 | + act = cut->value( colors ) |
| 50 | + exp = 92 ). |
| 51 | + ENDMETHOD. |
| 52 | + |
| 53 | + METHOD test_orange_and_orange. |
| 54 | + DATA(colors) = VALUE string_table( ( `orange` ) ( `orange` ) ). |
| 55 | + cl_abap_unit_assert=>assert_equals( |
| 56 | + act = cut->value( colors ) |
| 57 | + exp = 33 ). |
| 58 | + ENDMETHOD. |
| 59 | + |
| 60 | + METHOD test_ignore_additional_colors. |
| 61 | + DATA(colors) = VALUE string_table( ( `green` ) ( `brown` ) ( `orange` ) ). |
| 62 | + cl_abap_unit_assert=>assert_equals( |
| 63 | + act = cut->value( colors ) |
| 64 | + exp = 51 ). |
| 65 | + ENDMETHOD. |
| 66 | + |
| 67 | + METHOD test_black_and_brown_one_digit. |
| 68 | + DATA(colors) = VALUE string_table( ( `black` ) ( `brown` ) ). |
| 69 | + cl_abap_unit_assert=>assert_equals( |
| 70 | + act = cut->value( colors ) |
| 71 | + exp = 1 ). |
| 72 | + ENDMETHOD. |
| 73 | + |
| 74 | +ENDCLASS. |
0 commit comments