cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

expand_to_grid.c (2473B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "common/rect.h"
     21
     22#include <CUnit/CUnit.h>
     23
     24/**
     25 * Test which verifies guac_common_rect_expand_to_grid() properly shifts and
     26 * resizes rectangles to fit an NxN grid.
     27 */
     28void test_rect__expand_to_grid() {
     29
     30    int cell_size = 16;
     31
     32    guac_common_rect max;
     33    guac_common_rect rect;
     34
     35    /* Simple adjustment */
     36    guac_common_rect_init(&rect, 0, 0, 25, 25);
     37    guac_common_rect_init(&max, 0, 0, 100, 100);
     38    guac_common_rect_expand_to_grid(cell_size, &rect, &max);
     39    CU_ASSERT_EQUAL(0, rect.x);
     40    CU_ASSERT_EQUAL(0, rect.y);
     41    CU_ASSERT_EQUAL(32, rect.width);
     42    CU_ASSERT_EQUAL(32, rect.height);
     43
     44    /* Adjustment with moving of rect */
     45    guac_common_rect_init(&rect, 75, 75, 25, 25);
     46    guac_common_rect_init(&max, 0, 0, 100, 100);
     47    guac_common_rect_expand_to_grid(cell_size, &rect, &max);
     48    CU_ASSERT_EQUAL(max.width - 32, rect.x);
     49    CU_ASSERT_EQUAL(max.height - 32, rect.y);
     50    CU_ASSERT_EQUAL(32, rect.width);
     51    CU_ASSERT_EQUAL(32, rect.height);
     52
     53    guac_common_rect_init(&rect, -5, -5, 25, 25);
     54    guac_common_rect_init(&max, 0, 0, 100, 100);
     55    guac_common_rect_expand_to_grid(cell_size, &rect, &max);
     56    CU_ASSERT_EQUAL(0, rect.x);
     57    CU_ASSERT_EQUAL(0, rect.y);
     58    CU_ASSERT_EQUAL(32, rect.width);
     59    CU_ASSERT_EQUAL(32, rect.height);
     60
     61    /* Adjustment with moving and clamping of rect */
     62    guac_common_rect_init(&rect, 0, 0, 25, 15);
     63    guac_common_rect_init(&max, 0, 5, 32, 15);
     64    guac_common_rect_expand_to_grid(cell_size, &rect, &max);
     65    CU_ASSERT_EQUAL(max.x, rect.x);
     66    CU_ASSERT_EQUAL(max.y, rect.y);
     67    CU_ASSERT_EQUAL(max.width, rect.width);
     68    CU_ASSERT_EQUAL(max.height, rect.height);
     69
     70}
     71