Debian Codegraph @

pencil/test/unit/draw_classifier_contour_test.c

raw
1 /* File: draw_classifier_contour_test.c; Copyright and License: see below */
2
3 #include "draw_classifier_contour_test.h"
4 #include "draw/draw_classifier_contour.h"
5 #include "entity/data_classifier_type.h"
6 #include "test_fixture.h"
7 #include "test_expect.h"
8 #include "test_environment_assert.h"
9 #include "test_case_result.h"
10
11 static test_fixture_t * set_up();
12 static void tear_down( test_fixture_t *fix );
13 static test_case_result_t test_calc_inner_area_and_back( test_fixture_t *fix );
14 static test_case_result_t test_calc_inner_area_too_small( test_fixture_t *fix );
15
16 test_suite_t draw_classifier_contour_test_get_suite(void)
17 {
18 test_suite_t result;
19 test_suite_init( &result,
20 "draw_classifier_contour_test_get_suite",
21 TEST_CATEGORY_UNIT | TEST_CATEGORY_CONTINUOUS | TEST_CATEGORY_COVERAGE,
22 &set_up,
23 &tear_down
24 );
25 test_suite_add_test_case( &result, "test_calc_inner_area_and_back", &test_calc_inner_area_and_back );
26 test_suite_add_test_case( &result, "test_calc_inner_area_too_small", &test_calc_inner_area_too_small );
27 return result;
28 }
29
30 struct test_fixture_struct {
31 pencil_size_t pencil_size; /*!< the pencil size object needed for tested functions */
32 };
33 typedef struct test_fixture_struct test_fixture_t; /* double declaration as reminder */
34 static test_fixture_t test_fixture;
35
36 static test_fixture_t * set_up()
37 {
38 test_fixture_t *fix = &test_fixture;
39 pencil_size_init( &((*fix).pencil_size), 640.0, 480.0 );
40 return fix;
41 }
42
43 static void tear_down( test_fixture_t *fix )
44 {
45 pencil_size_destroy( &((*fix).pencil_size) );
46 }
47
48 static test_case_result_t test_calc_inner_area_and_back( test_fixture_t *fix )
49 {
50 draw_classifier_contour_t contour_calculator;
51 draw_classifier_contour_init( &contour_calculator );
52
53 const geometry_rectangle_t outer_bounds_before = { .left = 100.0, .top = 90.0, .width = 110.0, .height = 80.0 };
54
55 for ( unsigned int t_idx = 0; t_idx < DATA_CLASSIFIER_TYPE_COUNT; t_idx ++ )
56 {
57 data_classifier_type_t classifier_type = DATA_CLASSIFIER_TYPE_ARRAY[ t_idx ];
58 /* printf(" type: %d\n", t_idx); */
59
60 const geometry_rectangle_t inner_area
61 = draw_classifier_contour_calc_inner_area( &contour_calculator,
62 classifier_type,
63 &outer_bounds_before,
64 &((*fix).pencil_size)
65 );
66
67 TEST_EXPECT( geometry_rectangle_is_containing( &outer_bounds_before, &inner_area ) );
68 TEST_EXPECT( ! geometry_rectangle_is_empty( &inner_area ) );
69
70 const geometry_rectangle_t outer_bounds_after
71 = draw_classifier_contour_calc_outer_bounds( &contour_calculator,
72 classifier_type,
73 &inner_area,
74 &((*fix).pencil_size)
75 );
76
77 TEST_EXPECT_EQUAL_DOUBLE( 100.0, geometry_rectangle_get_left( &outer_bounds_after ) );
78 TEST_EXPECT_EQUAL_DOUBLE( 90.0, geometry_rectangle_get_top( &outer_bounds_after ) );
79 TEST_EXPECT_EQUAL_DOUBLE( 110.0, geometry_rectangle_get_width( &outer_bounds_after ) );
80 TEST_EXPECT_EQUAL_DOUBLE( 80.0, geometry_rectangle_get_height( &outer_bounds_after ) );
81 }
82
83 draw_classifier_contour_destroy( &contour_calculator );
84 return TEST_CASE_RESULT_OK;
85 }
86
87 static test_case_result_t test_calc_inner_area_too_small( test_fixture_t *fix )
88 {
89 draw_classifier_contour_t contour_calculator;
90 draw_classifier_contour_init( &contour_calculator );
91
92 const double gap = pencil_size_get_standard_object_border( &((*fix).pencil_size) );
93
94 const geometry_rectangle_t outer_bounds = { .left = 0.0, .top = 0.0, .width = gap, .height = gap };
95
96 const data_classifier_type_t classifier_type = DATA_CLASSIFIER_TYPE_USE_CASE;
97
98 const geometry_rectangle_t inner_area
99 = draw_classifier_contour_calc_inner_area( &contour_calculator,
100 classifier_type,
101 &outer_bounds,
102 &((*fix).pencil_size)
103 );
104
105 TEST_EXPECT_EQUAL_DOUBLE( 0.0, geometry_rectangle_get_width( &inner_area ) );
106 TEST_EXPECT_EQUAL_DOUBLE( 0.0, geometry_rectangle_get_height( &inner_area ) );
107
108 draw_classifier_contour_destroy( &contour_calculator );
109 return TEST_CASE_RESULT_OK;
110 }
111
112
113 /*
114 * Copyright 2021-2026 Andreas Warnke
115 *
116 * Licensed under the Apache License, Version 2.0 (the "License");
117 * you may not use this file except in compliance with the License.
118 * You may obtain a copy of the License at
119 *
120 * http://www.apache.org/licenses/LICENSE-2.0
121 *
122 * Unless required by applicable law or agreed to in writing, software
123 * distributed under the License is distributed on an "AS IS" BASIS,
124 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125 * See the License for the specific language governing permissions and
126 * limitations under the License.
127 */