1+ *"* use this source file for your ABAP unit test classes
2+ CLASS ltcl_resistor_color_trio DEFINITION FINAL FOR TESTING
3+ DURATION SHORT
4+ RISK LEVEL HARMLESS .
5+
6+ PRIVATE SECTION .
7+ DATA cut TYPE REF TO zcl_resistor_color_trio.
8+ METHODS setup.
9+ METHODS :
10+ test_orange_and_orange_black FOR TESTING ,
11+ test_blue_and_grey_brown FOR TESTING ,
12+ test_red_and_black_red FOR TESTING ,
13+ test_green_and_brown_orange FOR TESTING ,
14+ test_yellow_and_violet_yellow FOR TESTING ,
15+ test_blue_and_violet_blue FOR TESTING ,
16+ test_minimum_possible_value FOR TESTING ,
17+ test_maximum_possible_value FOR TESTING ,
18+ test_invalid_octal FOR TESTING ,
19+ test_ignore_extra_colors FOR TESTING .
20+ ENDCLASS .
21+
22+ CLASS ltcl_resistor_color_trio IMPLEMENTATION .
23+
24+ METHOD setup .
25+ cut = NEW zcl_resistor_color_trio( ).
26+ ENDMETHOD .
27+
28+ METHOD test_orange_and_orange_black .
29+ DATA (input_colors ) = VALUE string_table( ( `orange` ) ( `orange` ) ( `black` ) ).
30+ cl_abap_unit_assert=>assert_equals(
31+ act = cut->label( input_colors )
32+ exp = '33 ohms' ).
33+ ENDMETHOD .
34+
35+ METHOD test_blue_and_grey_brown .
36+ DATA (input_colors ) = VALUE string_table( ( `blue` ) ( `grey` ) ( `brown` ) ).
37+ cl_abap_unit_assert=>assert_equals(
38+ act = cut->label( input_colors )
39+ exp = '680 ohms' ).
40+ ENDMETHOD .
41+
42+ METHOD test_red_and_black_red .
43+ DATA (input_colors ) = VALUE string_table( ( `red` ) ( `black` ) ( `red` ) ).
44+ cl_abap_unit_assert=>assert_equals(
45+ act = cut->label( input_colors )
46+ exp = '2 kiloohms' ).
47+ ENDMETHOD .
48+
49+ METHOD test_green_and_brown_orange .
50+ DATA (input_colors ) = VALUE string_table( ( `green` ) ( `brown` ) ( `orange` ) ).
51+ cl_abap_unit_assert=>assert_equals(
52+ act = cut->label( input_colors )
53+ exp = '51 kiloohms' ).
54+ ENDMETHOD .
55+
56+ METHOD test_yellow_and_violet_yellow .
57+ DATA (input_colors ) = VALUE string_table( ( `yellow` ) ( `violet` ) ( `yellow` ) ).
58+ cl_abap_unit_assert=>assert_equals(
59+ act = cut->label( input_colors )
60+ exp = '470 kiloohms' ).
61+ ENDMETHOD .
62+
63+ METHOD test_blue_and_violet_blue .
64+ DATA (input_colors ) = VALUE string_table( ( `blue` ) ( `violet` ) ( `blue` ) ).
65+ cl_abap_unit_assert=>assert_equals(
66+ act = cut->label( input_colors )
67+ exp = '67 megaohms' ).
68+ ENDMETHOD .
69+
70+ METHOD test_minimum_possible_value .
71+ DATA (input_colors ) = VALUE string_table( ( `black` ) ( `black` ) ( `black` ) ).
72+ cl_abap_unit_assert=>assert_equals(
73+ act = cut->label( input_colors )
74+ exp = '0 ohms' ).
75+ ENDMETHOD .
76+
77+ METHOD test_maximum_possible_value .
78+ DATA (input_colors ) = VALUE string_table( ( `white` ) ( `white` ) ( `white` ) ).
79+ cl_abap_unit_assert=>assert_equals(
80+ act = cut->label( input_colors )
81+ exp = '99 gigaohms' ).
82+ ENDMETHOD .
83+
84+ METHOD test_invalid_octal .
85+ DATA (input_colors ) = VALUE string_table( ( `black` ) ( `grey` ) ( `black` ) ).
86+ cl_abap_unit_assert=>assert_equals(
87+ act = cut->label( input_colors )
88+ exp = '8 ohms' ).
89+ ENDMETHOD .
90+
91+ METHOD test_ignore_extra_colors .
92+ DATA (input_colors ) = VALUE string_table( ( `blue` ) ( `green` ) ( `yellow` ) ( `orange` ) ).
93+ cl_abap_unit_assert=>assert_equals(
94+ act = cut->label( input_colors )
95+ exp = '650 kiloohms' ).
96+ ENDMETHOD .
97+
98+ ENDCLASS .
0 commit comments