|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +#import <XCTest/XCTest.h> |
| 12 | +#import <ComponentKit/CKInternalHelpers.h> |
| 13 | +#import <ComponentKit/CKSizeRange.h> |
| 14 | + |
| 15 | +@interface CKSizeRangeTests : XCTestCase |
| 16 | + |
| 17 | +@end |
| 18 | + |
| 19 | +@implementation CKSizeRangeTests |
| 20 | + |
| 21 | +static bool verifySizeRange(CKSizeRange &sz,CGSize &size) { |
| 22 | + return CKIsGreaterThanOrEqualWithTolerance(sz.max.width, size.width) |
| 23 | + && CKIsGreaterThanOrEqualWithTolerance(size.width, sz.min.width) |
| 24 | + && CKIsGreaterThanOrEqualWithTolerance(sz.max.height,size.height) |
| 25 | + && CKIsGreaterThanOrEqualWithTolerance(size.height,sz.min.height); |
| 26 | +} |
| 27 | + |
| 28 | +- (void)testExactMatch { |
| 29 | + CKSizeRange sz(CGSizeMake(400, 400), CGSizeMake(400, 400)); |
| 30 | + CGSize s = CGSizeMake(400, 400); |
| 31 | + XCTAssert(verifySizeRange(sz, s)); |
| 32 | +} |
| 33 | + |
| 34 | +- (void)testRangeMatch { |
| 35 | + CKSizeRange sz(CGSizeMake(0, 0), CGSizeMake(INFINITY, INFINITY)); |
| 36 | + CGSize s = CGSizeMake(400, 400); |
| 37 | + XCTAssert(verifySizeRange(sz, s)); |
| 38 | +} |
| 39 | + |
| 40 | +- (void)testNaNMatch { |
| 41 | + CKSizeRange sz(CGSizeMake(NAN, NAN), CGSizeMake(NAN, NAN)); |
| 42 | + CGSize s = CGSizeMake(NAN, NAN); |
| 43 | + XCTAssert(verifySizeRange(sz, s)); |
| 44 | +} |
| 45 | + |
| 46 | +- (void)testVerySmallDifferenceMatch { |
| 47 | + CKSizeRange sz(CGSizeMake(374.99999999999994, 400), CGSizeMake(374.99999999999994, 400)); |
| 48 | + CGSize s = CGSizeMake(375, 400); |
| 49 | + XCTAssert(verifySizeRange(sz, s)); |
| 50 | +} |
| 51 | + |
| 52 | +- (void)testVerySmallDifferenceRangeMatch { |
| 53 | + CKSizeRange sz(CGSizeMake(0, 380), CGSizeMake(INFINITY, 400)); |
| 54 | + CGSize s = CGSizeMake(400, 379.99999999999994); |
| 55 | + XCTAssert(verifySizeRange(sz, s)); |
| 56 | +} |
| 57 | + |
| 58 | +@end |
0 commit comments