Skip to content

Commit

Permalink
[Shape Scheme] Addition of Unit Tests for the Shape Scheme (#5137)
Browse files Browse the repository at this point in the history
This resolves #5047
  • Loading branch information
yarneo committed Sep 17, 2018
1 parent a7810bb commit f43e3e7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/schemes/Shape/src/MDCShapeCategory.m
Expand Up @@ -41,4 +41,20 @@ - (instancetype)initCornersWithFamily:(MDCShapeCornerFamily)cornerFamily
return self;
}

- (BOOL)isEqual:(id)object {
if (object == self) {
return YES;
}

if (!object || ![[object class] isEqual:[self class]]) {
return NO;
}

MDCShapeCategory *other = (MDCShapeCategory *)object;
return [_topLeftCorner isEqual:other.topLeftCorner] &&
[_topRightCorner isEqual:other.topRightCorner] &&
[_bottomLeftCorner isEqual:other.bottomLeftCorner] &&
[_bottomRightCorner isEqual:other.bottomRightCorner];
}

@end
71 changes: 71 additions & 0 deletions components/schemes/Shape/tests/unit/MDCShapeSchemeTests.m
@@ -0,0 +1,71 @@
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import <XCTest/XCTest.h>

#import "MaterialMath.h"
#import "MaterialShapeLibrary.h"
#import "MaterialShapeScheme.h"

@interface MDCShapeSchemeTests : XCTestCase
@end

@implementation MDCShapeSchemeTests

- (void)testShapeCategoryEquality {
// Given
MDCShapeCategory *cat1 =
[[MDCShapeCategory alloc] initCornersWithFamily:MDCShapeCornerFamilyAngled andSize:2.1f];
MDCShapeCategory *cat2 = [[MDCShapeCategory alloc] init];
MDCCornerTreatment *corner =
[MDCCornerTreatment cornerWithCut:2.1f valueType:MDCCornerTreatmentValueTypeAbsolute];
cat2.topLeftCorner = corner;
cat2.topRightCorner = corner;
cat2.bottomLeftCorner = corner;
cat2.bottomRightCorner = corner;

// Then
XCTAssertEqualObjects(cat1, cat2);
}

- (void)testInitMatchesInitWithMaterialDefaults {
// Given
MDCShapeScheme *initScheme = [[MDCShapeScheme alloc] init];
MDCShapeScheme *mdDefaultScheme =
[[MDCShapeScheme alloc] initWithDefaults:MDCShapeSchemeDefaultsMaterial201809];

// Then
XCTAssertEqualObjects(initScheme.largeSurfaceShape, mdDefaultScheme.largeSurfaceShape);
XCTAssertEqualObjects(initScheme.mediumSurfaceShape, mdDefaultScheme.mediumSurfaceShape);
XCTAssertEqualObjects(initScheme.smallSurfaceShape, mdDefaultScheme.smallSurfaceShape);
}

- (void)testInitWithMaterialDefaults {
// Given
MDCShapeScheme *shapeScheme =
[[MDCShapeScheme alloc] initWithDefaults:MDCShapeSchemeDefaultsMaterial201809];

// Then
XCTAssertEqualObjects(shapeScheme.largeSurfaceShape,
[[MDCShapeCategory alloc] initCornersWithFamily:MDCShapeCornerFamilyRounded
andSize:0.f]);
XCTAssertEqualObjects(shapeScheme.mediumSurfaceShape,
[[MDCShapeCategory alloc] initCornersWithFamily:MDCShapeCornerFamilyRounded
andSize:4.f]);
XCTAssertEqualObjects(shapeScheme.smallSurfaceShape,
[[MDCShapeCategory alloc] initCornersWithFamily:MDCShapeCornerFamilyRounded
andSize:4.f]);
}

@end

0 comments on commit f43e3e7

Please sign in to comment.