Main Content

matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues

클래스: matlab.unittest.constraints.PublicPropertyComparator
네임스페이스: matlab.unittest.constraints

모든 값을 재귀적으로 지원하는 퍼블릭 속성에 대한 비교 연산자

설명

예제

c = matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues는 MATLAB® 객체 배열의 퍼블릭 속성에 대한 비교 연산자를 만듭니다. 이 비교 연산자는 재귀적으로 동작하며 퍼블릭 속성에 포함된 모든 데이터형을 지원합니다.

예제

c = matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues(Name,Value)는 하나 이상의 이름-값 인수를 사용하여 옵션을 추가로 설정합니다. 예를 들어, c = matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues("IgnoringCase",true)는 대/소문자를 무시하는 비교 연산자를 만듭니다.

입력 인수

모두 확장

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

예: c = matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues(IgnoringCase=true)

R2021a 이전 릴리스에서는 쉼표를 사용하여 각 이름과 값을 구분하고 Name을 따옴표로 묶으십시오.

예: c = matlab.unittest.constraints.PublicPropertyComparator.supportingAllValues("IgnoringCase",true)

텍스트 값 비교 시 대/소문자 무시 여부로, 숫자형 또는 논리값 0(false) 또는 1(true)로 지정됩니다. 기본적으로 비교 연산자는 대/소문자를 구분합니다.

텍스트 값을 비교할 때 공백 무시 여부로, 숫자형 또는 논리값 0(false) 또는 1(true)로 지정됩니다. 기본적으로 비교 연산자는 공백을 무시하지 않습니다. 공백 문자로는 공백(' '), 폼 피드('\f'), 새 줄('\n'), 캐리지 리턴('\r'), 가로 탭('\t'), 세로 탭('\v')이 있습니다.

구조체형 배열 비교 시 무시할 필드로, string형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. 비교 연산자는 지정된 필드의 값을 비교하지 않습니다.

예: "IgnoringFields","field1"

MATLAB 객체 배열 비교 시 무시할 속성으로, string형 배열 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. 비교 연산자는 지정된 속성의 값을 비교하지 않습니다.

예: "IgnoringProperties","Property1"

비교 중에 사용할 허용오차로, matlab.unittest.constraints.Tolerance 객체로 지정됩니다.

예: "Within",matlab.unittest.constraints.AbsoluteTolerance(1)

예: "Within",matlab.unittest.constraints.AbsoluteTolerance(1) | matlab.unittest.constraints.RelativeTolerance(0.1)

특성

Statictrue

메서드의 특성에 대해 자세히 알아보려면 메서드 특성을 참조하십시오.

예제

모두 확장

모든 데이터형을 지원하는 비교 연산자를 사용하여 두 객체의 퍼블릭 속성을 비교합니다.

현재 폴더에 있는 Student.m이라는 파일에서 Student 클래스를 만듭니다. 이 클래스는 두 개의 퍼블릭 속성과 하나의 프라이빗 속성을 가집니다.

classdef Student
    properties (SetAccess=immutable)
        Name
        Age
    end
    properties (Access=private)
        Field
    end
    methods
        function obj = Student(name,age,field)
            arguments
                name = "";
                age = [];
                field = "";
            end
            obj.Name = name;
            obj.Age = age;
            obj.Field = field;
        end
    end
end

이 예제에서 사용되는 클래스를 가져옵니다.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsEqualTo
import matlab.unittest.constraints.PublicPropertyComparator

대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.

testCase = TestCase.forInteractiveUse;

2개의 Student 객체를 만들고 IsEqualTo 제약 조건을 사용하여 이 둘을 비교합니다. 이 예제에서는 프라이빗 속성의 값이 서로 다르기 때문에 테스트가 실패합니다.

s1 = Student("Mary Jones",20,"physics");
s2 = Student("Mary Jones",20,"biology");
testCase.verifyThat(s1,IsEqualTo(s2))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEqualTo failed.
    --> ObjectComparator failed.
        --> The objects are not equal using "isequaln".
        
        Actual Value:
          Student with properties:
        
            Name: "Mary Jones"
             Age: 20
        Expected Value:
          Student with properties:
        
            Name: "Mary Jones"
             Age: 20
    ------------------
    Stack Information:
    ------------------
    In C:\work\ComparePublicPropertiesExample.m (ComparePublicPropertiesExample) at 29

PublicPropertyComparator 인스턴스를 사용하여 테스트를 반복합니다. Name 속성과 Age 속성은 서로 다른 유형이므로 모든 데이터형을 지원하는 비교 연산자를 사용하여 비교를 수행합니다. s1.Fields2.Field의 값이 서로 다르더라도, 비교 연산자가 s1s2의 퍼블릭 속성만 검사하므로 테스트가 통과합니다.

testCase.verifyThat(s1,IsEqualTo(s2, ...
    "Using",PublicPropertyComparator.supportingAllValues))
Verification passed.

Student 객체를 새로 만들고 s1과 비교합니다. s1.Names3.Name의 값이 서로 다르므로 테스트가 실패합니다.

s3 = Student("mary jones",20,"chemistry");
testCase.verifyThat(s1,IsEqualTo(s3, ...
    "Using",PublicPropertyComparator.supportingAllValues))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEqualTo failed.
    --> Path to failure: <Value>.Name
        --> StringComparator failed.
            --> The strings are not equal.
            
            Actual Value:
                "Mary Jones"
            Expected Value:
                "mary jones"
    
    Actual Value:
      Student with properties:
    
        Name: "Mary Jones"
         Age: 20
    Expected Value:
      Student with properties:
    
        Name: "mary jones"
         Age: 20
    ------------------
    Stack Information:
    ------------------
    In C:\work\ComparePublicPropertiesExample.m (ComparePublicPropertiesExample) at 44

테스트가 통과하도록 하기 위해, 대/소문자를 무시하는 비교 연산자를 사용합니다.

testCase.verifyThat(s1,IsEqualTo(s3, ...
    "Using",PublicPropertyComparator.supportingAllValues( ...
    "IgnoringCase",true)))
Verification passed.

또는 비교 연산자가 비교 중에 Name 속성을 무시하도록 설정할 수 있습니다.

testCase.verifyThat(s1,IsEqualTo(s3, ...
    "Using",PublicPropertyComparator.supportingAllValues( ...
    "IgnoringProperties","Name")))
Verification passed.

제한 사항

  • PublicPropertyComparator 클래스는 subsref, numel, properties 함수 중 하나를 오버로드하는 객체의 퍼블릭 속성을 지원하지 않습니다.

버전 내역

R2014a에 개발됨