1# Copyright 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Tests for zoom_capture_utils.""" 15 16 17import unittest 18 19import zoom_capture_utils 20 21 22_CIRCLE_X = 320 23_CIRCLE_Y = 240 24_FOCAL_LENGTH = 1 25_IMG_SIZE = (640, 480) 26_OFFSET_RTOL = 0.1 27_RADIUS_RTOL = 0.1 28 29 30def _generate_valid_zoom_results(): 31 return [ 32 zoom_capture_utils.ZoomTestData( 33 result_zoom=1, 34 circle=[_CIRCLE_X, _CIRCLE_Y, 1], 35 radius_tol=_RADIUS_RTOL, 36 offset_tol=_OFFSET_RTOL, 37 focal_length=_FOCAL_LENGTH 38 ), 39 zoom_capture_utils.ZoomTestData( 40 result_zoom=2, 41 circle=[_CIRCLE_X, _CIRCLE_Y, 2], 42 radius_tol=_RADIUS_RTOL, 43 offset_tol=_OFFSET_RTOL, 44 focal_length=_FOCAL_LENGTH 45 ), 46 zoom_capture_utils.ZoomTestData( 47 result_zoom=3, 48 circle=[_CIRCLE_X, _CIRCLE_Y, 3], 49 radius_tol=_RADIUS_RTOL, 50 offset_tol=_OFFSET_RTOL, 51 focal_length=_FOCAL_LENGTH 52 ), 53 zoom_capture_utils.ZoomTestData( 54 result_zoom=4, 55 circle=[_CIRCLE_X, _CIRCLE_Y, 4], 56 radius_tol=_RADIUS_RTOL, 57 offset_tol=_OFFSET_RTOL, 58 focal_length=_FOCAL_LENGTH 59 ), 60 ] 61 62 63class ZoomCaptureUtilsTest(unittest.TestCase): 64 """Unit tests for this module.""" 65 66 def setUp(self): 67 super().setUp() 68 self.zoom_results = _generate_valid_zoom_results() 69 70 def test_verify_zoom_results_enough_zoom_data(self): 71 self.assertTrue( 72 zoom_capture_utils.verify_zoom_results( 73 self.zoom_results, _IMG_SIZE, 4, 1 74 ) 75 ) 76 77 def test_verify_zoom_results_not_enough_zoom(self): 78 self.assertFalse( 79 zoom_capture_utils.verify_zoom_results( 80 self.zoom_results, _IMG_SIZE, 5, 1 81 ) 82 ) 83 84 def test_verify_zoom_results_wrong_zoom(self): 85 self.zoom_results[-1].result_zoom = 5 86 self.assertFalse( 87 zoom_capture_utils.verify_zoom_results( 88 self.zoom_results, _IMG_SIZE, 4, 1 89 ) 90 ) 91 92 def test_verify_zoom_results_wrong_offset(self): 93 self.zoom_results[-1].circle[0] = 640 94 self.assertFalse( 95 zoom_capture_utils.verify_zoom_results( 96 self.zoom_results, _IMG_SIZE, 4, 1 97 ) 98 ) 99 100 101if __name__ == '__main__': 102 unittest.main() 103