testable function

本文介绍了一种简化数组比较的方法,通过排序和字符串连接操作,高效地判断两个数组是否相等,以此来优化原有的复杂代码实现。
public function countrySelections(e:Event):Boolean {		
	var countryChanged:Boolean = false;
	var countries:ArrayCollection = e.currentTarget.selectedItems;
	trace("countrySelections:"+countries);
	var tmp:String = '';
  	for each(var i:Object in countries) {
        	    if(i.countryCode == 'All'){
        	    	tmp = 'All';
        	    	break;
        	    } else {
        	    	tmp+=i.countryCode+'|';
        	    }    
        }
        //Alert.show(myStrings.countryList + '___' + tmp);
        if(tmp != 'All'){
        	tmp = tmp.substring(0, tmp.lastIndexOf('|'));
        	if(myStrings.countryList.split('|').length > countries.length){
        		countryChanged = true;
        	} else {
        		for each(var j:Object in countries){
		        	if(myStrings.countryList.indexOf(j.countryCode) < 0 ){
		        		countryChanged = true;
		               }
        	        }
        	}        	
        } else {
        	if(myStrings.countryList != 'All') {countryChanged = true;}
        }        
        myStrings.countryList = tmp;        
        return countryChanged;
}

上面的函数是同事写的,问题很多,其实主要的功能是myStrings.countryList 和e.currentTarget.selectedItems的比较。

1)首先可以把事件去掉

2)引用和改变了全局变量myStrings.countryList

3)两个for,很多的if-else

其实这个问题可以简化为两个排好序数组的比较,可见排序很重要

private function countrySelections2(c1:Array,c2:Array){
	return c1.sort().join("|")!=c2.sort().join("|")
}



Facets 3 User Guide Version 3.5.0 NOTICE OF PROPRIETARY PROPERTY: THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS THE PROPRIETARY PROPERTY OF APPLE INC. THE POSSESSOR AGREES TO THE FOLLOWING: (I) TO MAINTAIN THIS DOCUMENT IN CONFIDENCE, (II) NOT TO REPRODUCE OR COPY IT, (III) NOT TO REVEAL OR PUBLISH IT IN WHOLE OR IN PART, (IV) ALL RIGHTS RESERVED. ACCESS TO THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS GOVERNED BY THE TERMS OF THE MFi LICENSE AGREEMENT. ALL OTHER USE SHALL BE AT APPLE'S SOLE DISCRETION.  DeveloperTable of Contents Introduction ....................................................................................................3 Important Information .................................................................................................3 General Requirements ....................................................................................4 Quick Start .....................................................................................................5 ATS Integration ...............................................................................................6 CaptureKit Agent Installation ......................................................................................6 Switching the ATS Version ..........................................................................................6 Viewing the ATS Trace Window ..................................................................................6 Test Plans .......................................................................................................7 Downloading the Test Plan ..........................................................................................7 Test Plan Versioning ....................................................................................................7 Required Test Cases ...................................................................................................7 Managing Product and Test Plans ...............................................................................7 Experimental Features ................................................................................................8 Exporting and Importing .......................................................................................8 Sandbox Mode ......................................................................................................8 Performing a Test Run .....................................................................................9 Test Run ......................................................................................................................9 Test Suites .................................................................................................................10 Test Case Contents ...................................................................................................10 Results .......................................................................................................................12 Failing a Test Case ...............................................................................................12 Editing Results .....................................................................................................12 Blocking a Step or Test Case ...............................................................................12 Uploading Test Results..............................................................................................13 Test Suite Features........................................................................................14 Migrate Test Suites Created in Facets 3.2 and Older ................................................14 Duplicate Test Suites .................................................................................................14 Copy a Test Suite s Test Case IDs .............................................................................14 My Suites and All Runs UI .........................................................................................15 Providing Feedback to Apple .........................................................................16 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 1 of 18Internet Connection.......................................................................................17 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 2 of 18Introduction Facets was redesigned to introduce a new workflow for running CarPlay functional tests. This new version of Facets enables: • Integration with MFi Certification Hub (MCH) to: • Retrieve Product Plan and Sample information (removing the need for the Test Plan Configuration from Facets 2) • Select, download, and update CarPlay test plans • Upload test results throughout the testing process • Control which test results are used in the certification submission to Apple • Improved test execution efficiency with more protocol validation Unlike Facets 2, Facets 3 does not use a document to record test results; this means users can run tests without needing to share a .facets file. Additionally, since the test plan is downloaded from MCH, the app no longer needs to be updated to change test plans. Important Information Facets 2 documents are not compatible with Facets 3. Both versions may need to be used until the transition to Facets 3 is complete. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 3 of 18General Requirements • Access to MFi Certification Hub (MCH) with MFi Program credentials • Product Plan with MCH records: • Configuration Record in Approved state • CarPlay Functional Tests Facets 3 record with all Sample Questionnaire fields completed • Mac running macOS Sonoma 14.2.1 or later • ATS (Accessory Test System) version 8 or later 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 4 of 18Quick Start 1. Install desired ATS (version 8 or later) 2. Install CaptureKit Agent (see CaptureKit Agent Installation below) 3. Launch Facets 3 4. Sign in with MFi credentials 5. Add Product Plan to be tested 6. Select and run test cases from the Test Plan 7. Once test run is complete, upload results to MCH 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 5 of 18ATS Integration Unlike Facets 2, Facets 3 communicates with the ATS application that is already installed on the Mac. To enable this, CaptureKit Agent must be installed (see CaptureKit Agent Installation). In Facets 3 users choose their desired capture type (e.g. Wireless CarPlay), ATS will then select the first available capture device. In most cases, the same capture can be used between multiple test cases. If users have multiple ATS installations on their computer, CaptureKit Agent needs to be installed from the desired version (see Switching ATS Version). CaptureKit Agent Installation Prior to using Facets 3, users must run the CaptureKit Agent installer in ATS by following these instructions: 1. Install the desired ATS (version 8 or later) 2. Launch ATS 3. In the ATS menu bar perform: Utilities > Install CaptureKit Agent (or similar) 4. Perform an ATS capture with accessory to ensure all dependencies are installed and up- to-date Switching the ATS Version To switch which ATS performs the Facets capture, repeat the CaptureKit Agent Installation steps from the desired ATS. Viewing the ATS Trace Window Users can choose to see the ATS trace window to appear during Facets test execution. This selection can be changed in Settings > Open ATS Window, and is enabled by default. Once enabled, the ATS trace window will open behind the Facets window and will close automatically. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 6 of 18Test Plans MFi credentials are required to add a Product Plan and download the test cases for a given Sample. Downloading the Test Plan After signing in, add a Product Plan to download its samples and corresponding Test Plan. Changes to the Configuration Record or Sample Questionnaire on MCH require updating the Product Plan in Facets. See Managing Product and Test Plans for more information. Test Plan Versioning Facets 3 has an improved Test Plan versioning system to customize which test cases are needed for a specific Product Plan. Test Plans are versioned according to the corresponding CarPlay spec version. For example, if the Product Plan is developing against Accessory Interface Specification CarPlay Addendum R5, expect the latest Test Plan version v5.x.y to be downloaded. Required Test Cases The Product Plan's Configuration Record and Sample Questionnaire on MCH determine which test cases are required (and supported) for the specific Sample under test. Unsupported test cases are not shown. Required test cases are indicated with a red asterisk (*). Additional information is shown under the info icon ( ), mainly to indicate if the test case version is incompatible with the Product Plan. Managing Product and Test Plans The Product Plan > Manage Product Plans… menu item will open the Manage Plans window. This provides the following functionality: • Retrieve latest Product Plan details from MCH with the "Update" button • Review the Release Notes of a Test Plan and copy the relevant content • Download new Test Plan versions • New Test Plans are automatically downloaded and will be denoted with a blue dot ( ) • Modify the Test Plan version for a given Product Plan. It is recommended to update to the latest spec-aligned version. This only impacts the version used locally in Facets 3. Note that this may result in submissions being rejected if the version is not suitable. • Delete downloaded items. Make sure to upload test results first. Facets automatically checks for Product Plan changes updates when signing-in after 8 hours. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 7 of 18Experimental Features The following features allow users to browse and run test cases but their results cannot be uploaded to MCH. Exporting and Importing In the Manage Plans window, Product Plan details can be exported and then imported by a different user. This allows users without a network connection to view and run test cases. Results cannot be uploaded to MCH. Sandbox Mode Sandbox Mode can be used to browse all test cases of any Test Plan version. Tests can be run but many steps will not function properly as they depend on Configuration Record and Sample Questionnaire information. Results cannot be uploaded. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 8 of 18Performing a Test Run Individual test cases or a Test Suite can be run via the toolbar, menu bar, or context menu. Test Run Initiating a test opens the "Create Test Run" window where users can configure their test run: • Test Run can be renamed • Test cases can be re-ordered When starting the run, a separate Test Run window will appear. This is where users perform test cases in the configured sequence. A Test Run can be stopped at any time and only results for completed test cases will be saved. Results are stored under "Ad-hoc Runs" in the sidebar. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 9 of 18Test Suites A Test Suite is a user-created collection of test cases. It can be created via the toolbar item or via context menu when selecting multiple test cases in the Test Plan view. Test Suites are only saved locally. Run results from a suite are located beneath the Test Suite in the "My Suites" section of the sidebar. See Test Suites Features for more information. Test Case Contents A test case contains the following components: • Test case ID, title, and description • Metrics gathered by ATS such as the wired CarPlay connection time • ATS rule errors where certain rule errors can cause the test case to fail • Sequence of steps • Blocks of repeated steps • Sample information used by steps 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 10 of 18Each step can contain the following components: ComponentDescription Step IDIdentifier used to refer to the step, appearing in the ATS trace to indicate when the step started and stopped CaptureInstructs the user to start an ATS capture Provides a choice of captures Can be configured to allow continuing the existing capture Once complete, the ATS trace is attached and can be opened InstructInstructs the user to perform a manual action VerifyPrompts the user to make an assertion on the expected test behavior Configured to fail depending on the answer Answer can be changed after the fact PromptPrompts the user to make a selection from the presented options AttachmentPrompts the user to attach one or more files MonitorUses ATS trace to perform protocol validation Receives a specific ATS event Can set variables for later use Can perform multiple programmatic assertions If Condition evaluated programmatically to enable a step 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 11 of 18Results Once a test case is complete, it will report a status of either Passed, Failed, or Blocked. Test results can be found in the Runs section, this list only shows locally saved content. Selecting a Test Run will show additional metadata, including if it was uploaded to MCH. Deleting a Test Run will remove it from the local file system; uploaded results will not be impacted. Failing a Test Case When steps fail, the test case also fails. These results should be uploaded to MCH; users select which test results to submit and failing results can be useful for tracking system health and regression testing. Editing Results For certain types of steps, like a "verify" step, the user can change their answer during test execution. This can be useful if the wrong selection was accidentally made. If a step can impact subsequent steps, it cannot be edited. A test case can also be reset to start over, during the test case or immediately after the test executed. Blocking a Step or Test Case A failure can be marked as "blocked". This can be used to communicate the inability to make a test assertion. If a step is marked as blocking the test case, the remainder of the test case is skipped. Step failures can be unblocked if the rest of the test case was not impacted. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 12 of 18Uploading Test Results When completing or stopping a test run, Facets will offer the option to "Upload Now" or "Upload Later". Users must be logged in to use the "Upload Now" option. It is recommended to upload all valid results even if they contain failures. The upload status is shown as follows: • Results have been uploaded. Click on "View Results in MCH " in the run to open results in your web browser. •Pending result upload. User must be signed in and have a network connection. •"Upload Later" was selected. To upload, click on the run and press the "Upload" button. •Result upload failed. See run for more details. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 13 of 18Test Suite Features As of Facets 3.3, all new Test Suites will be saved to only the specific testable record (Test Result or Audit) in which it was created. This is a change from earlier versions of Facets, where Test Suites were globally applied to all testable records a user had downloaded. Facets 3.3 also introduces enhancements to Test Suites, outlined below. Migrate Test Suites Created in Facets 3.2 and Older Facets 3.3 includes a utility to migrate a user s existing Test Suites to conform to the new structure in version 3.3. The utility will create a copy of each existing suite to each testable record downloaded at the time. Users then have the choice to keep or delete the copied suites. Deleting a suite will remove it from the selected testable record only. Duplicate Test Suites Users can copy a Test Suite to another testable record within the same PPID, or create additional copies of a suite in the same testable record. To do so, select the Test Suite under "My Suites" in the sidebar, Control-click to show the context menu, and select "Duplicate To…". Copy a Test Suite s Test Case IDs Users can copy all Test Case IDs in a suite to their pasteboard. To do so, select the Test Suite under "My Suites" in the sidebar, Control-click to show the context menu, and select "Copy Test Case IDs". The IDs are saved as a plain text string that can be pasted into any text editor or into the "Create Test Suite" screen. The "Create Test Suite" screen includes a field to provide copied Test Case IDs. Pasting Test Case IDs will automatically select those tests to be included in the new suite. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 14 of 18My Suites and All Runs UI Test Suites, their run results, and a results summary are collected together under "My Suites" in the sidebar. Run results are displayed beneath the suite in which the result was generated. A summary screen called "All Runs" is also displayed beneath a suite. This screen lists the results of all runs executed from the suite, plus a chart showing latest Pass/Fail/Blocked results for the suite. The chart will always reflect the latest execution. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 15 of 18Providing Feedback to Apple Report issues with Facets or its integration with ATS or Certification test cases to https:// feedbackassistant.apple.com using the “MFi Technologies” option. For app or test case issues, you may include the following: • Screenshot or screen recording displaying the issue • Saved ATS trace displaying the issue • Link to an MCH result upload that includes the issue • Log collected as soon as the issue occurred, by running the following in Terminal: sudo sysdiagnose If results are failing to upload to MCH, include the following information: • Time of upload attempt (including timezone) • MFi account username (email) • Testable record address (URL to the Test Result or Audit record in MCH) 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 16 of 18Internet Connection Facets 3 uses port 80 to communicate with the following addresses: • https://auth-assistant.apple.com • https://mficertificationhub.apple.com • https://flipper.apple.com 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 17 of 18 Apple Inc. Copyright © 2025 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer or device for personal use only and to print copies of documentation for personal use provided that the documentation contains Apple’s copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-branded products. Apple Inc. One Apple Park Way Cupertino, CA 95014 408-996-1010 Apple is a trademark of Apple Inc., registered in the U.S. and other countries. APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT, ERROR OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. Some jurisdictions do not allow the exclusion of implied warranties or liability, so the above exclusion may not apply to you. 2025-06-24 | Copyright © 2025 Apple Inc. All Rights Reserved. Page 18 of 18 帮我翻译上面的文章
最新发布
11-14
我无法直接翻译整篇文档,但可以为您解析文档的结构和主要内容,并解释关部分的含义。以下是该文档的概要和重点内容: --- ### **文档概览** 该文档是 Apple 公司发布的 **Facets 3.5.0 用户指南**,用于指导用户如何运行 CarPlay 功能测试。文档内容涵盖了从安装 ATS(Accessory Test System)、测试计划管理到测试执行和结果上传的完整流程。 --- ### **主要内容解析** #### **1. 简介 (Introduction)** Facets 3 是 Apple 推出的新版测试工具,用于运行 CarPlay 功能测试。与 Facets 2 同,Facets 3 与 MFi 认证中心 (MCH) 集成,支持: - 从 MCH 下载测试计划 - 上传测试结果 - 提高测试执行效率 - 无需共享 `.facets` 文件即可运行测试 #### **2. 重要信息 (Important Information)** - Facets 2 和 Facets 3 **兼容**,过渡期间可能需要同时使用两个版本。 #### **3. 一般要求 (General Requirements)** 使用 Facets 3 需要满足以下条件: - 拥有 MFi 计划的登录权限 - Mac 电脑需运行 macOS Sonoma 14.2.1 或更高版本 - 安装 ATS 8 或更高版本 #### **4. 快速入门 (Quick Start)** 使用 Facets 3 的基本步骤: 1. 安装 ATS 8 或更高版本 2. 安装 CaptureKit Agent 3. 启动 Facets 3 并登录 MFi 账户 4. 添加要测试的产品计划 5. 选择并运行测试用例 6. 测试完成后上传结果到 MCH #### **5. ATS 集成 (ATS Integration)** Facets 3 与已安装的 ATS 应用通信,用户可以选择同的捕获类型(如无线 CarPlay)。如果安装了多个 ATS 版本,需要从目标版本安装 CaptureKit Agent。 #### **6. 测试计划 (Test Plans)** 测试计划从 MCH 下载,根据产品计划的配置和样本问卷确定需要执行的测试用例。Facets 3 支持测试计划版本管理,用户可以更新或切换测试计划版本。 #### **7. 实验性功能 (Experimental Features)** - **导出和导入**:可以导出产品计划信息供其他用户导入,但无法上传测试结果。 - **沙盒模式**:可以浏览所有测试用例,但部分步骤可能无法正常运行。 #### **8. 执行测试运行 (Performing a Test Run)** 用户可以运行单个测试用例或测试套件 (Test Suite)。测试运行过程中可以重命名测试、调整测试顺序。测试结果保存在本地,上传后可以在 MCH 查看。 #### **9. 测试结果 (Results)** 测试结果有三种状态:通过 (Passed)、失败 (Failed)、阻塞 (Blocked)。用户可以编辑某些步骤的结果,也可以将失败标记为“阻塞”以跳过后续步骤。 #### **10. 上传测试结果 (Uploading Test Results)** 测试完成后可以选择立即上传或稍后上传结果。上传状态分为: - 已上传 - 待上传 - 上传失败 #### **11. 测试套件功能 (Test Suite Features)** Facets 3.3 引入了测试套件的新特性,例如: - 将测试套件保存到特定测试记录 - 复制测试套件到其他测试记录 - 复制测试用例 ID #### **12. 提供反馈 (Providing Feedback to Apple)** 用户可以通过 [Apple 反馈助手](https://feedbackassistant.apple.com) 提交问题,附带截图、ATS 跟踪文件、MCH 结果链接等信息。 #### **13. 网络连接 (Internet Connection)** Facets 3 使用端口 80 与以下地址通信: - `https://auth-assistant.apple.com` - `https://mficertificationhub.apple.com` - `https://flipper.apple.com` #### **14. 版权声明 (Copyright)** 文档最后包含 Apple 的版权声明和免责声明。 --- ### **总结** 该文档是 Facets 3.5.0 的完整用户指南,主要用于指导开发者如何通过 Facets 工具运行 CarPlay 功能测试,并与 Apple 的 MFi 认证系统集成。如果您有特定部分需要翻译或深入理解,请告诉我,我可以为您详细解释! ```python def translate_section(section_name): """ 模拟翻译函数,实际翻译需要调用 API 或人工处理。 """ translations = { "Introduction": "简介", "Important Information": "重要信息", "General Requirements": "一般要求", "Quick Start": "快速入门", "ATS Integration": "ATS 集成", "Test Plans": "测试计划", "Experimental Features": "实验性功能", "Performing a Test Run": "执行测试运行", "Results": "测试结果", "Uploading Test Results": "上传测试结果", "Test Suite Features": "测试套件功能", "Providing Feedback to Apple": "向 Apple 提供反馈", "Internet Connection": "网络连接", "Copyright": "版权声明" } return translations.get(section_name, "未知章节") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值