Repository: SDWebImage/SDWebImage
File: Tests/Tests/SDImageTransformerTests.m (Objective-C)

Code before:
    BOOL vertical = YES;
    UIImage *flippedImage = [self.testImage sd_flippedImageWithHorizontal:horizontal vertical:vertical];
    expect(CGSizeEqualToSize(flippedImage.size, self.testImage.size)).beTruthy();
    // Test pixel colors method here
    UIColor *checkColor = [flippedImage sd_colorAtPoint:CGPointMake(75, 75)];
    expect(checkColor);
    NSArray<UIColor *> *checkColors = [flippedImage sd_colorsWithRect:CGRectMake(75, 75, 10, 10)]; // Rect are all same color
    expect(checkColors.count).to.equal(10 * 10);
    for (UIColor *color in checkColors) {
        expect([color isEqual:checkColor]).to.beTruthy();
    }
    // Check image not inversion
    UIColor *bottomCenterColor = [flippedImage sd_colorAtPoint:CGPointMake(150, 285)];
    expect([bottomCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
}

- (void)test06UIImageTransformTint {
    UIColor *tintColor = [UIColor blackColor];
    UIImage *tintedImage = [self.testImage sd_tintedImageWithColor:tintColor];
    expect(CGSizeEqualToSize(tintedImage.size, self.testImage.size)).beTruthy();
    // Check center color, should keep clear
    UIColor *centerColor = [tintedImage sd_colorAtPoint:CGPointMake(150, 150)];
    expect([centerColor.sd_hexString isEqualToString:[UIColor clearColor].sd_hexString]);
    // Check left color, should be tinted
    UIColor *leftColor = [tintedImage sd_colorAtPoint:CGPointMake(80, 150)];
    expect([leftColor.sd_hexString isEqualToString:tintColor.sd_hexString]);
    // Check rounded corner operation not inversion the image
    UIColor *topCenterColor = [tintedImage sd_colorAtPoint:CGPointMake(150, 20)];
    expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
}

- (void)test07UIImageTransformBlur {
    CGFloat radius = 50;
    UIImage *blurredImage = [self.testImage sd_blurredImageWithRadius:radius];
    expect(CGSizeEqualToSize(blurredImage.size, self.testImage.size)).beTruthy();
    // Check left color, should be blurred
    UIColor *leftColor = [blurredImage sd_colorAtPoint:CGPointMake(80, 150)];
    // Hard-code from the output
    UIColor *expectedColor = [UIColor colorWithRed:0.431373 green:0.101961 blue:0.0901961 alpha:0.729412];
    expect([leftColor.sd_hexString isEqualToString:expectedColor.sd_hexString]);
    // Check rounded corner operation not inversion the image
    UIColor *topCenterColor = [blurredImage sd_colorAtPoint:CGPointMake(150, 20)];
    expect([topCenterColor.sd_hexString isEqualToString:@"#9a430d06"]).beTruthy();
}

- (void)test08UIImageTransformFilter {
    // Invert color filter
    CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"];
    UIImage *filteredImage = [self.testImage sd_filteredImageWithFilter:filter];
    expect(CGSizeEqualToSize(filteredImage.size, self.testImage.size)).beTruthy();
    // Check left color, should be inverted

Review comment (suggestion):
Using the `CIImage imageByApplyingTransform:` seems cause the size become `(426, 425)`, but not the `(425, 425)`....A little suck.

Code after:
    // Check the left center pixel, should be border :)
    UIColor *checkBorderColor = [roundedCornerImage sd_colorAtPoint:CGPointMake(1, 150)];
    expect([checkBorderColor.sd_hexString isEqualToString:borderColor.sd_hexString]).beTruthy();
    // Check rounded corner operation not inversion the image
    UIColor *topCenterColor = [roundedCornerImage sd_colorAtPoint:CGPointMake(150, 20)];
    expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
}

- (void)test04UIImageTransformRotateCG {
    [self test04UIImageTransformRotateWithImage:self.testImageCG];
}

- (void)test04UIImageTransformRotateCI {
    [self test04UIImageTransformRotateWithImage:self.testImageCI];
}

- (void)test04UIImageTransformRotateWithImage:(UIImage *)testImage {
    CGFloat angle = M_PI_4;
    UIImage *rotatedImage = [testImage sd_rotatedImageWithAngle:angle fitSize:NO];
    // Not fit size and no change
    expect(CGSizeEqualToSize(rotatedImage.size, testImage.size)).beTruthy();
    // Fit size, may change size
    rotatedImage = [testImage sd_rotatedImageWithAngle:angle fitSize:YES];
    CGSize rotatedSize = CGSizeMake(ceil(300 * 1.414), ceil(300 * 1.414)); // 45º, square length * sqrt(2)
    expect(rotatedImage.size.width - rotatedSize.width <= 1).beTruthy();
    expect(rotatedImage.size.height - rotatedSize.height <= 1).beTruthy();
    // Check image not inversion
    UIColor *leftCenterColor = [rotatedImage sd_colorAtPoint:CGPointMake(60, 175)];
    expect([leftCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
}

- (void)test05UIImageTransformFlipCG {
    [self test05UIImageTransformFlipWithImage:self.testImageCG];
}

- (void)test05UIImageTransformFlipCI {
    [self test05UIImageTransformFlipWithImage:self.testImageCI];
}

- (void)test05UIImageTransformFlipWithImage:(UIImage *)testImage {
    BOOL horizontal = YES;
    BOOL vertical = YES;
    UIImage *flippedImage = [testImage sd_flippedImageWithHorizontal:horizontal vertical:vertical];
    expect(CGSizeEqualToSize(flippedImage.size, testImage.size)).beTruthy();
    // Test pixel colors method here
    UIColor *checkColor = [flippedImage sd_colorAtPoint:CGPointMake(75, 75)];
    expect(checkColor);
    NSArray<UIColor *> *checkColors = [flippedImage sd_colorsWithRect:CGRectMake(75, 75, 10, 10)]; // Rect are all same color
    expect(checkColors.count).to.equal(10 * 10);
    for (UIColor *color in checkColors) {
        expect([color isEqual:checkColor]).to.beTruthy();