matlab.unittest.constraints.TableComparator 클래스
네임스페이스: matlab.unittest.constraints
table형 배열의 비교 연산자
설명
matlab.unittest.constraints.TableComparator
클래스는 MATLAB® table형 배열의 비교 연산자를 제공합니다. 테스트에 이 비교 연산자를 사용하려면 TableComparator
인스턴스를 만들고 IsEqualTo
제약 조건 생성자의 Using
이름-값 인수의 값으로 지정합니다.
생성
설명
c = matlab.unittest.constraints.TableComparator
는 빈 table형 배열의 비교 연산자를 만듭니다. 이 비교 연산자는 실제 값과 예상 값이 크기와 속성값이 동일한 빈 table형 배열인 경우에 충족됩니다.
c = matlab.unittest.constraints.TableComparator(
는 지정된 비교 연산자 comp
)comp
를 사용하여 table형 배열에 포함된 값을 비교합니다. 이 구문을 사용하면 이 비교 연산자는 실제 값과 예상 값이 크기와 속성값이 동일한 table형 배열이고 해당 테이블 변수가 comp
비교 연산자를 만족하는 경우에 충족됩니다.
입력 인수
comp
— 테이블 변수의 값을 비교하는 데 사용하는 비교 연산자
비교 연산자 클래스의 객체 배열
테이블 변수에 포함된 값을 비교하는 데 사용하는 비교 연산자로, matlab.unittest.constraints
네임스페이스에서 비교 연산자로 분류되는 클래스의 객체 배열로 지정됩니다.
예: matlab.unittest.constraints.NumericComparator
예: matlab.unittest.constraints.StringComparator("IgnoringCase",true)
예: [matlab.unittest.constraints.LogicalComparator matlab.unittest.constraints.NumericComparator]
tf
— 재귀적으로 동작을 수행할지 여부
false
또는 0
(디폴트 값) | true
또는 1
재귀적으로 동작을 수행할지 여부로, 숫자형 또는 논리값 0
(false
) 또는 1
(true
)로 지정됩니다.
값이 true
이면 실제 table형 배열과 예상 table형 배열의 변수는 table형 배열도 될 수 있으며, 비교 연산자는 이러한 변수를 재귀적으로 비교합니다. 값이 false
이면 실제 table형 배열과 예상 table형 배열의 모든 변수는 comp
에서 지원하는 유형을 가져야 합니다. 예를 들어, 다음 코드에서는 c1
과 c2
모두 숫자형 값으로 구성된 table형 배열을 비교할 수 있습니다. 그러나 오로지 c2
만이 table형 배열을 변수로 포함하는 table형 배열이나 숫자형 값을 변수로 포함하는 table형 배열을 비교할 수 있습니다.
import matlab.unittest.constraints.TableComparator import matlab.unittest.constraints.NumericComparator c1 = TableComparator(NumericComparator); c2 = TableComparator(NumericComparator,"Recursively",true);
이 인수는 Recursive
속성을 설정합니다.
속성
예제
빈 테이블 비교하기
TableComparator
클래스를 사용하여 빈 테이블을 비교합니다.
먼저 이 예제에서 사용되는 클래스를 가져옵니다.
import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.TableComparator
대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.
testCase = TestCase.forInteractiveUse;
TableComparator
인스턴스를 사용하여 2개의 빈 테이블을 비교합니다. table
과 table.empty
가 동일하게 빈 테이블인지 확인합니다.
testCase.verifyThat(table,IsEqualTo(table.empty,"Using",TableComparator))
Verification passed.
서로 다른 속성값을 갖는 2개의 빈 테이블이 동일한지 테스트합니다. 테스트가 실패합니다.
T1 = table; T1.Properties.Description = "First Empty Table"; T2 = table; T2.Properties.Description = "Second Empty Table"; testCase.verifyThat(T1,IsEqualTo(T2,"Using",TableComparator))
Verification failed. --------------------- Framework Diagnostic: --------------------- IsEqualTo failed. --> TableComparator failed. --> Table properties do not match. Path to failure: <table>.Properties --> ObjectComparator failed. --> The objects are not equal using "isequaln". Actual Value: TableProperties with properties: Description: 'First Empty Table' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {1×0 cell} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties. Expected Value: TableProperties with properties: Description: 'Second Empty Table' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {1×0 cell} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties. Actual Value: 0×0 empty table Expected Value: 0×0 empty table ------------------ Stack Information: ------------------ In C:\work\CompareEmptyTablesExample.m (CompareEmptyTablesExample) at 25
비어 있지 않은 테이블 비교하기
TableComparator
클래스를 사용하여 비어 있지 않은 변수를 포함하는 테이블을 비교합니다.
먼저 이 예제에서 사용되는 클래스를 가져옵니다.
import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.TableComparator import matlab.unittest.constraints.NumericComparator import matlab.unittest.constraints.AbsoluteTolerance
대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.
testCase = TestCase.forInteractiveUse;
변수에 숫자형 값이 포함된 테이블을 2개 만듭니다.
LastName = ["Lin";"Jones";"Brown"]; Age = [38;40;49]; Height = [64;67;64]; Weight = [131;133;119]; BloodPressure = [125 83; 117 75; 122 80]; T1 = table(Age,Height,Weight,BloodPressure); T2 = table(Age,Height,Weight,BloodPressure,'RowNames',LastName);
TableComparator
인스턴스를 사용하여 테이블을 비교합니다. 비어 있지 않은 테이블을 비교하려면 적절한 비교 연산자를 TableComparator
생성자에 전달합니다.
testCase.verifyThat(T1,IsEqualTo(T2, ... "Using",TableComparator(NumericComparator)))
Verification failed. --------------------- Framework Diagnostic: --------------------- IsEqualTo failed. --> TableComparator failed. --> Table properties do not match. Path to failure: <table>.Properties --> ObjectComparator failed. --> The objects are not equal using "isequaln". Actual Value: TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Age' 'Height' 'Weight' 'BloodPressure'} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties. Expected Value: TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Age' 'Height' 'Weight' 'BloodPressure'} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {3×1 cell} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties. Actual Value: 3×4 table Age Height Weight BloodPressure ___ ______ ______ _____________ 38 64 131 125 83 40 67 133 117 75 49 64 119 122 80 Expected Value: 3×4 table Age Height Weight BloodPressure ___ ______ ______ _____________ Lin 38 64 131 125 83 Jones 40 67 133 117 75 Brown 49 64 119 122 80 ------------------ Stack Information: ------------------ In C:\work\CompareNonemptyTablesExample.m (CompareNonemptyTablesExample) at 30
테이블 변수에 동일한 숫자형 데이터가 포함되어 있어도 T1
과 T2
에서 RowNames
속성의 값이 다르기 때문에 이 테스트는 실패합니다. 테스트가 통과하도록 하기 위해, T1
에서 RowNames
속성을 설정합니다.
T1.Properties.RowNames = LastName; testCase.verifyThat(T1,IsEqualTo(T2, ... "Using",TableComparator(NumericComparator)))
Verification passed.
T2
에 포함된 값 중 하나를 변경하고 테이블을 다시 비교합니다. 테스트가 실패합니다.
T2.Age(end) = 50; testCase.verifyThat(T1,IsEqualTo(T2, ... "Using",TableComparator(NumericComparator)))
Verification failed. --------------------- Framework Diagnostic: --------------------- IsEqualTo failed. --> Path to failure: <Value>.Age --> NumericComparator failed. --> The numeric values are not equal using "isequaln". --> Failure table: Index Actual Expected Error RelativeError _____ ______ ________ _____ _____________ 3 49 50 -1 -0.02 Actual Value: 38 40 49 Expected Value: 38 40 50 Actual Value: 3×4 table Age Height Weight BloodPressure ___ ______ ______ _____________ Lin 38 64 131 125 83 Jones 40 67 133 117 75 Brown 49 64 119 122 80 Expected Value: 3×4 table Age Height Weight BloodPressure ___ ______ ______ _____________ Lin 38 64 131 125 83 Jones 40 67 133 117 75 Brown 50 64 119 122 80 ------------------ Stack Information: ------------------ In C:\work\CompareNonemptyTablesExample.m (CompareNonemptyTablesExample) at 43
테이블 변수 내 대응하는 값들이 절대 허용오차 1 내에서 동일해야 한다고 지정합니다. 테스트가 통과합니다.
testCase.verifyThat(T1,IsEqualTo(T2, ... "Using",TableComparator( ... NumericComparator("Within",AbsoluteTolerance(1)))))
Verification passed.
테이블이 중첩 테이블을 포함하도록 수정합니다. 수정된 테이블을 비교하기 위해 TableComparator
가 재귀적으로 동작하도록 지시합니다. 테스트가 통과합니다.
T1.BloodPressure = table([125;117;122],[83;75;80]); T2 = T1; testCase.verifyThat(T1,IsEqualTo(T2, ... "Using",TableComparator(NumericComparator,"Recursively",true)))
Verification passed.
팁
대부분의 경우에는
TableComparator
인스턴스를 사용할 필요가 없습니다.IsEqualTo
클래스는 table형 배열을 포함하여 다양한 데이터형의 동일성을 테스트하는 제약 조건을 만듭니다.IsEqualTo
클래스가 수행하는 비교를 재정의해야 하는 경우TableComparator
인스턴스를 사용하십시오. 예를 들어, table형 배열이 숫자가 아닌 값을 포함하는 경우 비교가 실패하도록 하려면 테스트에TableComparator
인스턴스를 포함하십시오. 다음 예제에서는 실제 테이블과 예상 테이블이 숫자형이 아닌 값을 포함하므로 MATLAB이 오류를 발생시킵니다.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.TableComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = table([45;32;34],logical([1;0;0]),'VariableNames',["Age" "Vote"]); act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",TableComparator(NumericComparator)))
버전 내역
R2017a에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)